dnd-kit icon indicating copy to clipboard operation
dnd-kit copied to clipboard

Deactivate keyboard sensor on blur

Open jperals opened this issue 1 year ago • 2 comments

This fixes https://github.com/clauderic/dnd-kit/issues/857.

As stated in that issue, this cannot be fixed by extending the KeyboardSensor, because all methods are private and this also creates other problems —but adding these changes in the main KeyboardSensor class works as expected. Moreover, I think it makes sense to deactivate dragging on blur as a general case in order to keep the UX consistent with the native browser focus —otherwise this leads to an inconsistent experience where a non-focused element keeps being interactive, which hurts usability and accessibility.

This works for losing focus in any way, therefore both by clicking with the mouse somewhere else or by typing Tab, even though in the latter case the (native) focus will stay on the active draggable element and a new Tab is required to navigate to the next focusable element, because of RestoreFocus. But since that can be overridden by setting restoreFocus to false in the DndContext, I did not include more changes in this PR in order to keep it minimal.

jperals avatar Mar 28 '23 17:03 jperals