-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: add onKeyDown prop to ListBoxItem for custom keyboard handling
#9181
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?
Conversation
onKeyDown prop to ListBoxItem for custom keyboard handlingonKeyDown prop to ListBoxItem for custom keyboard handling
snowystinger
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for starting this, would you mind removing the docs and storybook in favour of a unit test? it can be added just after this describe block
| describe('press events', () => { |
|
|
||
| The `<ListBoxItem>` component works with frameworks and client side routers like [Next.js](https://nextjs.org/) and [React Router](https://reactrouter.com/en/main). As with other React Aria components that support links, this works via the <TypeLink links={docs.links} type={docs.exports.RouterProvider} /> component at the root of your app. See the [client side routing guide](routing.html) to learn how to set this up. | ||
|
|
||
| ## Custom keyboard handling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to document this, it'll be in the props table and is a pretty common pattern
|
Thanks for the review! I've addressed your feedback. Please take another look. |
|
This should be using |
| let {getAllByRole} = renderListbox({}, {onKeyDown}); | ||
| let options = getAllByRole('option'); | ||
|
|
||
| fireEvent.keyDown(options[0], {key: 'Delete'}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| fireEvent.keyDown(options[0], {key: 'Delete'}); | |
| await user.tab(); | |
| await user.keyboard('ArrowDown'); |
e7356f7 to
81ccc92
Compare
|
Fixed! I've updated the test to use userEvent.keyboard() instead of fireEvent.keyDown() to prevent event leaking 🙏 |
Closes #8732
Added
onKeyDownprop toListBoxItemto support custom keyboard event handling for individual items,enabling features like deleting items with Delete/Backspace keys.
✅ Pull Request Checklist:
Issue.
Practices
📝 Test Instructions:
yarn start🧢 Your Project:
Open source contribution