-
Notifications
You must be signed in to change notification settings - Fork 3.6k
fix: Keyboard Navigation: Track Distance: Map start/stop points cannot be reordered by using a keyboard #85124
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
base: main
Are you sure you want to change the base?
Changes from all commits
50256e6
6648de7
36c7e6c
50bda05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,38 +1,59 @@ | ||||||||||||||||||||||||||||||||||
| import {useSortable} from '@dnd-kit/sortable'; | ||||||||||||||||||||||||||||||||||
| import {CSS} from '@dnd-kit/utilities'; | ||||||||||||||||||||||||||||||||||
| import React from 'react'; | ||||||||||||||||||||||||||||||||||
| import React, {useLayoutEffect} from 'react'; | ||||||||||||||||||||||||||||||||||
| import CONST from '@src/CONST'; | ||||||||||||||||||||||||||||||||||
| import type {SortableItemProps} from './types'; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const PRESSABLE_SELECTOR = '[data-tag="pressable"]'; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| function SortableItem({id, children, disabled = false}: SortableItemProps) { | ||||||||||||||||||||||||||||||||||
| const {attributes, listeners, setNodeRef, transform, transition, isDragging} = useSortable({id, disabled}); | ||||||||||||||||||||||||||||||||||
| const {attributes, listeners, setNodeRef, transform, transition, isDragging, node} = useSortable({id, disabled}); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const style = { | ||||||||||||||||||||||||||||||||||
| touchAction: 'none', | ||||||||||||||||||||||||||||||||||
| transform: CSS.Transform.toString(transform), | ||||||||||||||||||||||||||||||||||
| transition, | ||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Prevent Enter key from reaching MenuItem when dragging to avoid navigation conflicts | ||||||||||||||||||||||||||||||||||
| // The sortable wrapper is the single Tab stop (tabIndex: 0 via dnd-kit attributes). | ||||||||||||||||||||||||||||||||||
| // Inner pressables must be non-focusable to avoid a double Tab stop per item. | ||||||||||||||||||||||||||||||||||
| useLayoutEffect(() => { | ||||||||||||||||||||||||||||||||||
| for (const el of node.current?.querySelectorAll<HTMLElement>(PRESSABLE_SELECTOR) ?? []) { | ||||||||||||||||||||||||||||||||||
| el.setAttribute('tabindex', '-1'); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+21
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We should handle cases where node.current might be null and separate the logic for better clarity and maintainability.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We intentionally use |
||||||||||||||||||||||||||||||||||
| }, [children, node]); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| const handleKeyDown = (e: React.KeyboardEvent) => { | ||||||||||||||||||||||||||||||||||
| if (!isDragging || e.key !== 'Enter') { | ||||||||||||||||||||||||||||||||||
| if (e.key !== CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey) { | ||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Block Enter during active drag | ||||||||||||||||||||||||||||||||||
| if (isDragging) { | ||||||||||||||||||||||||||||||||||
| e.preventDefault(); | ||||||||||||||||||||||||||||||||||
| e.stopPropagation(); | ||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| e.preventDefault(); | ||||||||||||||||||||||||||||||||||
| e.stopPropagation(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Forward Enter to the inner pressable for navigation | ||||||||||||||||||||||||||||||||||
| const innerPressable = node.current?.querySelector<HTMLElement>(PRESSABLE_SELECTOR); | ||||||||||||||||||||||||||||||||||
| if (innerPressable) { | ||||||||||||||||||||||||||||||||||
| innerPressable.click(); | ||||||||||||||||||||||||||||||||||
| e.preventDefault(); | ||||||||||||||||||||||||||||||||||
| e.stopPropagation(); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+39
to
+44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Same thing above
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this would change behavior |
||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| return ( | ||||||||||||||||||||||||||||||||||
| <div | ||||||||||||||||||||||||||||||||||
| ref={setNodeRef} | ||||||||||||||||||||||||||||||||||
| style={style} | ||||||||||||||||||||||||||||||||||
| // Use capture phase to intercept Enter before MenuItem handles it | ||||||||||||||||||||||||||||||||||
| // Use capture phase to intercept Enter before inner MenuItem handles it | ||||||||||||||||||||||||||||||||||
| onKeyDownCapture={handleKeyDown} | ||||||||||||||||||||||||||||||||||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||||||||||||||||||||||||||||||||||
| {...attributes} | ||||||||||||||||||||||||||||||||||
| // eslint-disable-next-line react/jsx-props-no-spreading | ||||||||||||||||||||||||||||||||||
| {...(disabled ? {} : listeners)} | ||||||||||||||||||||||||||||||||||
| // Override dnd-kit's tabIndex to prevent double focus (outer wrapper + inner MenuItem) | ||||||||||||||||||||||||||||||||||
| tabIndex={-1} | ||||||||||||||||||||||||||||||||||
| > | ||||||||||||||||||||||||||||||||||
| {children} | ||||||||||||||||||||||||||||||||||
| </div> | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.