Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unselecting the last element doesn't trigger move and stop #238

Open
carlos-algms opened this issue Nov 22, 2024 · 3 comments · May be fixed by #239
Open

Unselecting the last element doesn't trigger move and stop #238

carlos-algms opened this issue Nov 22, 2024 · 3 comments · May be fixed by #239
Assignees
Labels
unconfirmed Problem is not confirmed yet

Comments

@carlos-algms
Copy link

carlos-algms commented Nov 22, 2024

What is the problem?

Clicking on an element to select it and then clicking again to unselect it doesn't trigger the events move and stop events.

it can be fixed by removing the if

if (!elements.length) {
return;
}

Please provide the steps to reproduce and create a CodeSandbox.

https://codesandbox.io/p/sandbox/ynjtdj

Also, check the console.log

  1. Select elements by clicking or dragging a selection
  2. unselect and leave only 1 element
  3. click on that last element

Check the events were NOT triggered.

What is the expected behavior?

It should trigger the move and stop events and stop should contain the right stored data so we can trust it.

@carlos-algms carlos-algms added the unconfirmed Problem is not confirmed yet label Nov 22, 2024
@carlos-algms carlos-algms changed the title Unselecting the last element doesn't trigger move and stop events also doesn't update internal state Unselecting the last element doesn't trigger move and stop Nov 22, 2024
@carlos-algms
Copy link
Author

Hey @simonwep I've created this small PR #239 removing the block I found was blocking the events from being triggered.

I managed to test it locally by building and installing the local version.

Please let me know what you think.

@simonwep
Copy link
Owner

Hey @carlos-algms, thank's for the elaborate issue and reproduction! But I'm a little bit confused, because if it wouldn't emit the move and stop events even the simplest selections wouldn't work. I tried it locally and all events seemed to be triggered correctly:

selection-events

Also in your codesandbox you do a lot with timeouts inside of the callbacks, accessing the values after the might have been changed again by viselect. Could you elaborate what you believe is the issue here? Is it that you would expect stored to be empty if it's also listed in changed.removed in the stop event?

@carlos-algms
Copy link
Author

Hey, thanks for investigating it 😊.

The stop event you see comes from the clearSelection() call, not from the unselect().

{
  "added": [],
  "removed": [
    "A"
  ],
  "stored": [
    "A"  // note even tho it was removed, it's still included here.
  ]
}

and it should be

{
  "added": [],
  "removed": [
    "A"
  ],
  "stored": [] // I'd expect it to be empty, as it is the last event I'll receive.
}

I put a timeout there to check the internal state is updated after some time, and stored will be empty, but not on the last stop event.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed Problem is not confirmed yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants