Skip to content

Commit f1d2493

Browse files
committed
fix: remove custom keyboard handling example from ListBox docs and story
1 parent 139f601 commit f1d2493

File tree

2 files changed

+0
-83
lines changed

2 files changed

+0
-83
lines changed

packages/react-aria-components/docs/ListBox.mdx

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -409,47 +409,6 @@ By default, link items in a ListBox are not selectable, and only perform navigat
409409

410410
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.
411411

412-
## Custom keyboard handling
413-
414-
ListBox supports custom keyboard event handling on individual items via the `onKeyDown` prop on `ListBoxItem`. This enables you to implement additional keyboard interactions beyond the built-in selection and navigation behavior, such as deleting items with the <Keyboard>Backspace</Keyboard> or <Keyboard>Delete</Keyboard> keys.
415-
416-
```tsx example
417-
import {useListData} from 'react-stately';
418-
import type {Key} from 'react-aria-components';
419-
420-
function Example() {
421-
let list = useListData({
422-
initialItems: [
423-
{id: 1, name: 'Item 1'},
424-
{id: 2, name: 'Item 2'},
425-
{id: 3, name: 'Item 3'},
426-
{id: 4, name: 'Item 4'},
427-
{id: 5, name: 'Item 5'}
428-
]
429-
});
430-
431-
let handleKeyDown = (key: Key) => (e: React.KeyboardEvent) => {
432-
if (e.key === 'Delete' || e.key === 'Backspace') {
433-
e.preventDefault();
434-
list.remove(key);
435-
}
436-
};
437-
438-
return (
439-
<ListBox
440-
aria-label="ListBox with delete support"
441-
selectionMode="single"
442-
items={list.items}>
443-
{item => (
444-
<ListBoxItem onKeyDown={handleKeyDown(item.id)}>
445-
{item.name}
446-
</ListBoxItem>
447-
)}
448-
</ListBox>
449-
);
450-
}
451-
```
452-
453412
## Sections
454413

455414
ListBox supports sections in order to group options. Sections can be used by wrapping groups of items in a `ListBoxSection` element. A `<Header>` element may also be included to label the section.

packages/react-aria-components/stories/ListBox.stories.tsx

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212

1313
import {action} from '@storybook/addon-actions';
1414
import {Collection, DropIndicator, GridLayout, Header, ListBox, ListBoxItem, ListBoxProps, ListBoxSection, ListLayout, Separator, Text, useDragAndDrop, Virtualizer, WaterfallLayout} from 'react-aria-components';
15-
import {Key} from '@react-types/shared';
16-
import {Keyboard} from '@react-spectrum/text';
1715
import {ListBoxLoadMoreItem} from '../';
1816
import {LoadingSpinner, MyListBoxItem} from './utils';
1917
import {Meta, StoryFn, StoryObj} from '@storybook/react';
@@ -810,44 +808,4 @@ export let VirtualizedListBoxDndOnAction: ListBoxStory = () => {
810808
);
811809
};
812810

813-
export const ListBoxWithKeyboardDelete: ListBoxStory = () => {
814-
let initialItems = [
815-
{id: 1, name: 'Item 1'},
816-
{id: 2, name: 'Item 2'},
817-
{id: 3, name: 'Item 3'},
818-
{id: 4, name: 'Item 4'},
819-
{id: 5, name: 'Item 5'}
820-
];
821-
822-
let list = useListData({
823-
initialItems
824-
});
825-
826-
let handleKeyDown = (key: Key) => (e: React.KeyboardEvent) => {
827-
if (e.key === 'Delete' || e.key === 'Backspace') {
828-
e.preventDefault();
829-
list.remove(key);
830-
action('onDelete')(key);
831-
}
832-
};
833-
834-
return (
835-
<div style={{display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 12}}>
836-
<div style={{padding: 12, background: '#f0f0f0', borderRadius: 4}}>
837-
Press <Keyboard>Delete</Keyboard> or <Keyboard>Backspace</Keyboard> to remove the focused item.
838-
</div>
839-
<ListBox
840-
className={styles.menu}
841-
aria-label="ListBox with delete support"
842-
selectionMode="single"
843-
items={list.items}>
844-
{item => (
845-
<MyListBoxItem onKeyDown={handleKeyDown(item.id)}>
846-
{item.name}
847-
</MyListBoxItem>
848-
)}
849-
</ListBox>
850-
</div>
851-
);
852-
};
853811

0 commit comments

Comments
 (0)