feat: Keyboard shortcut handler#9929
Open
snowystinger wants to merge 19 commits intomainfrom
Open
Conversation
# Conflicts: # packages/react-aria/src/selection/useSelectableCollection.ts
|
Build successful! 🎉 |
|
Build successful! 🎉 |
|
Build successful! 🎉 |
|
Build successful! 🎉 |
snowystinger
commented
May 4, 2026
|
|
||
| const isSelected = selectedKey === key; | ||
|
|
||
| let onKeyDown = (event) => { |
Member
Author
There was a problem hiding this comment.
This seems just designed to skip arrow down and up, i think it'd be better to do this in the keyboard delegate or just allow it, i'm not sure why we wouldn't, there could be vertical steplists and it's a nice non-rtl dependent set of keys.
Just removing it for now as it'd make debugging difficult anyways
|
Build successful! 🎉 |
## API Changes
react-aria-components/react-aria-components:MenuSection MenuSection <T extends {}> {
aria-label?: string
children?: ReactNode | ({}) => ReactElement
className?: string = 'react-aria-MenuSection'
defaultSelectedKeys?: 'all' | Iterable<Key>
dependencies?: ReadonlyArray<any>
+ disabledKeys?: Iterable<Key>
disallowEmptySelection?: boolean
id?: Key
items?: Iterable<{}>
onSelectionChange?: (Selection) => void
selectedKeys?: 'all' | Iterable<Key>
selectionMode?: SelectionMode
shouldCloseOnSelect?: boolean
style?: CSSProperties
value?: {}
}/react-aria-components:MenuSectionProps MenuSectionProps <T> {
aria-label?: string
children?: ReactNode | (T) => ReactElement
className?: string = 'react-aria-MenuSection'
defaultSelectedKeys?: 'all' | Iterable<Key>
dependencies?: ReadonlyArray<any>
+ disabledKeys?: Iterable<Key>
disallowEmptySelection?: boolean
id?: Key
items?: Iterable<T>
onSelectionChange?: (Selection) => void
selectedKeys?: 'all' | Iterable<Key>
selectionMode?: SelectionMode
shouldCloseOnSelect?: boolean
style?: CSSProperties
value?: T
}@react-aria/interactions/@react-aria/interactions:KeyboardProps KeyboardProps {
+ ignorePortalRef?: RefObject<Element | null> | null
isDisabled?: boolean
onKeyDown?: (KeyboardEvent) => void
onKeyUp?: (KeyboardEvent) => void
+ shortcuts?: KeyboardShortcutBindings
}@react-spectrum/s2/@react-spectrum/s2:MenuSection MenuSection <T extends {}> {
aria-label?: string
children?: ReactNode | (T) => ReactElement
defaultSelectedKeys?: 'all' | Iterable<Key>
dependencies?: ReadonlyArray<any>
+ disabledKeys?: Iterable<Key>
disallowEmptySelection?: boolean
id?: Key
items?: Iterable<T>
onSelectionChange?: (Selection) => void
selectionMode?: SelectionMode
shouldCloseOnSelect?: boolean
value?: T
}/@react-spectrum/s2:MenuSectionProps MenuSectionProps <T extends {}> {
aria-label?: string
children?: ReactNode | (T) => ReactElement
defaultSelectedKeys?: 'all' | Iterable<Key>
dependencies?: ReadonlyArray<any>
+ disabledKeys?: Iterable<Key>
disallowEmptySelection?: boolean
id?: Key
items?: Iterable<T>
onSelectionChange?: (Selection) => void
selectionMode?: SelectionMode
shouldCloseOnSelect?: boolean
value?: T
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes
I'm ready for some initial reviews before I finish off converting the repo.
Aiming to help us solve the issue of event leaks, this will allow us more fine grained control of what useKeyboard blocks/prevents default on in a more declarative way.
New behaviour is opt in through
shortcutsinuseKeyboard. This will preventDefault and stopPropagation if the associated function in the map returns true. Or it will let the event pass without altering it if false is returned. In addition, an object can be returned to alter that behaviour in whatever way necessary. Given that all key combinations are exclusive matches, this should make it more obvious what events are continuing or not.✅ Pull Request Checklist:
📝 Test Instructions:
🧢 Your Project: