daybrush / selecto

Selecto.js is a component that allows you to select elements in the drag area using the mouse or touch.
https://daybrush.com/selecto
MIT License
2.04k stars 82 forks source link

How to use toggleContinueSelect to only add to the selection and not remove? #97

Closed emilionavarro closed 2 years ago

emilionavarro commented 2 years ago

Environments

Framework name: React Framework version: 17.0.2 Component name: React-Selecto Component version: 1.15.1

Description

I'm trying to use toggleContinueSelect to only add to the selection and never remove. So when you drag and select a previously selected item, it should not remove. But I can't find a good way to do this.

daybrush commented 2 years ago

@emilionavarro

What you are talking about is like the continueSelectWithoutDeselect option.

Use continueSelectWithoutDeselect with toggleContinueSelect.

If you want to use it with a toggle key, use toggleContinueSelectWithoutDeselect option.

Thank you :)

emilionavarro commented 2 years ago

I will play around with this and post my results.

Thank you @daybrush :)

emilionavarro commented 2 years ago

Thanks again, I believe this is working nicely.

For future references, here's the solution @daybrush suggested.

<Selecto
    dragContainer=".container"
    selectableTargets={['.item']}
    toggleContinueSelect="shift"
    toggleContinueSelectWithoutDeselect="shift"
    onSelect={(e) => {
            e.added.forEach((el) => el.classList.add('selected'));
            e.removed.forEach((el) => el.classList.remove('selected'));
    }}
/>

Where toggleContinueSelect and toggleContinueSelectWithoutDeselect work together to allow for selection without any deselection.