You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using useSortable in a modal, there is an issue with keyboard event propagation. Currently, keyboard events are not prevented from propagation, causing unintended behavior. The modal catches keydown event (Escape) before dnd-kit listeners do, and closes instead of canceling the drag and stopping the propagation.
Expected behavior:
I'd expect that when keyboard navigation is activated within the sortable items, keyboard events should be stopped from further propagation. This would ensure that the modal (or other components) does not receive and act upon keyboard events when it shouldn't.
Press Space or Enter to activate keyboard listeners
Press Escape
Notes
I tried to prevent event propagation before invoking useSortable listeners, but this breaks the cancel functionality. I discovered that these events are attached to the document, causing them to be fired at the very end, which looks like the main issue. To fix this, I created MyKeyboardSensor and overrode attach() and detach() methods to set events directly to the target, and added event.stopPropagation(), this fixed my issue. I'm curious is there any particular reason why events are set to the document and not to the target itself?
Also, I think listeners lack blur event handling, I'd expect that drag is canceled when this event is fired on the target element. Let me know if I should create a separate issue for this.
By the way, thanks for creating such an awesome library!
The text was updated successfully, but these errors were encountered:
When using
useSortable
in a modal, there is an issue with keyboard event propagation. Currently, keyboard events are not prevented from propagation, causing unintended behavior. The modal catcheskeydown
event (Escape
) beforednd-kit
listeners do, and closes instead of canceling the drag and stopping the propagation.Expected behavior:
I'd expect that when keyboard navigation is activated within the sortable items, keyboard events should be stopped from further propagation. This would ensure that the modal (or other components) does not receive and act upon keyboard events when it shouldn't.
Codesandbox example
https://codesandbox.io/p/sandbox/priceless-currying-8ytlml?file=%2Fsrc%2FSortable.js%3A48%2C1
Steps to reproduce
Tab
to focus on one of the itemsSpace
orEnter
to activate keyboard listenersEscape
Notes
I tried to prevent event propagation before invoking
useSortable
listeners, but this breaks the cancel functionality. I discovered that these events are attached to the document, causing them to be fired at the very end, which looks like the main issue. To fix this, I createdMyKeyboardSensor
and overrodeattach()
anddetach()
methods to set events directly to the target, and addedevent.stopPropagation()
, this fixed my issue. I'm curious is there any particular reason why events are set to the document and not to the target itself?Also, I think listeners lack
blur
event handling, I'd expect that drag is canceled when this event is fired on the target element. Let me know if I should create a separate issue for this.By the way, thanks for creating such an awesome library!
The text was updated successfully, but these errors were encountered: