Skip to content

Commit d3062f8

Browse files
Fix readonly ComboBox with focus menuTrigger (#6693)
Co-authored-by: Yihui Liao <[email protected]>
1 parent 3a9239d commit d3062f8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/@react-stately/combobox/src/useComboBoxState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export function useComboBoxState<T extends object>(props: ComboBoxStateOptions<T
321321
let setFocused = (isFocused: boolean) => {
322322
if (isFocused) {
323323
valueOnFocus.current = inputValue;
324-
if (menuTrigger === 'focus') {
324+
if (menuTrigger === 'focus' && !props.isReadOnly) {
325325
open(null, 'focus');
326326
}
327327
} else {

packages/react-aria-components/test/ComboBox.test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,13 @@ describe('ComboBox', () => {
283283
fireEvent.scroll(input); // simulate what happens when the text is long and overflows
284284
expect(listbox).toBeInTheDocument();
285285
});
286+
287+
it('should not open the menu when isReadOnly', async () => {
288+
let {getByRole, queryByRole} = render(<TestComboBox isReadOnly menuTrigger="focus" />);
289+
290+
let input = getByRole('combobox');
291+
await user.click(input);
292+
293+
expect(queryByRole('listbox')).not.toBeInTheDocument();
294+
});
286295
});

0 commit comments

Comments
 (0)