Skip to content

Commit a9e1ef1

Browse files
authoredMar 8, 2023
ListBox: avoid overriding Item id with custom id (adobe#4179)
1 parent 92ae3fd commit a9e1ef1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed
 

‎packages/@react-spectrum/listbox/src/ListBoxOption.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export function ListBoxOption<T>(props: OptionProps<T>) {
4545
key
4646
} = item;
4747
let domProps = filterDOMProps(item.props);
48+
delete domProps.id;
4849
let state = useContext(ListBoxContext);
4950

5051
let ref = useRef<HTMLDivElement>();

‎packages/@react-spectrum/listbox/test/ListBox.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,21 @@ describe('ListBox', function () {
730730
expect(option).toHaveAttribute('data-name', 'Foo');
731731
});
732732

733+
it('item id should not get overridden by custom id', function () {
734+
let items = [{key: 0, name: 'Foo'}, {key: 1, name: 'Bar'}];
735+
let {getByRole} = render(
736+
<Provider theme={theme}>
737+
<ListBox aria-label="listbox" items={items}>
738+
{item => <Item id={item.name}>{item.name}</Item>}
739+
</ListBox>
740+
</Provider>
741+
);
742+
act(() => jest.runAllTimers());
743+
let listbox = getByRole('listbox');
744+
let option = within(listbox).getAllByRole('option')[0];
745+
expect(option.id).not.toEqual('Foo');
746+
});
747+
733748
describe('async loading', function () {
734749
it('should display a spinner while loading', async function () {
735750
let {getByRole, rerender} = render(

0 commit comments

Comments
 (0)
Failed to load comments.