Skip to content

Commit 8384aa3

Browse files
authored
fix(Combobox): use stable selectedKeys to prevent infinite loop (adobe#9781)
1 parent dc3cbd5 commit 8384aa3

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

packages/@react-aria/combobox/src/useComboBox.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export function useComboBox<T, M extends SelectionMode = 'single'>(props: AriaCo
208208
state.setFocused(true);
209209
};
210210

211-
let valueId = useValueId([state.selectedItems, state.selectionManager.selectionMode]);
211+
let valueId = useValueId([state.selectionManager.selectedKeys, state.selectionManager.selectionMode]);
212212
let {isInvalid, validationErrors, validationDetails} = state.displayValidation;
213213
let {labelProps, inputProps, descriptionProps, errorMessageProps} = useTextField({
214214
...props,

packages/@react-aria/combobox/test/useComboBox.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,22 @@ describe('useComboBox', function () {
5252
jest.clearAllMocks();
5353
});
5454

55+
it('should not infinite loop when children is an inline function', function () {
56+
let {result} = renderHook(() => {
57+
let inlineProps = {
58+
items: [{id: 'a', name: 'Option A'}, {id: 'b', name: 'Option B'}],
59+
children: (item) => <Item key={item.id} textValue={item.name}>{item.name}</Item>,
60+
placeholder: 'Select...',
61+
allowsCustomValue: true,
62+
menuTrigger: 'focus'
63+
};
64+
let state = useComboBoxState(inlineProps);
65+
return useComboBox({...inlineProps, ...props}, state);
66+
});
67+
expect(result.current.inputProps).toBeDefined();
68+
expect(result.current.inputProps.role).toBe('combobox');
69+
});
70+
5571
it('should return default props for all the button group elements', function () {
5672
let {result} = renderHook(() => useComboBox(props, useComboBoxState(defaultProps)));
5773
let {buttonProps, inputProps, listBoxProps, labelProps} = result.current;

0 commit comments

Comments
 (0)