Deactivate keyboard sensor on blur #1087
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes #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 settingrestoreFocus
tofalse
in theDndContext
, I did not include more changes in this PR in order to keep it minimal.