Skip to content

Commit d40aa5a

Browse files
fix(ComboBox): Skip blur commits for read-only fields
Read-only ComboBoxes cannot change their selection or input, so skip committing a value when focus leaves the field. AI-assisted: Claude Code
1 parent 338cf2e commit d40aa5a

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,27 @@ describe('ComboBox', () => {
500500
expect(queryByRole('listbox')).not.toBeInTheDocument();
501501
});
502502

503+
it('should not fire change events on blur when isReadOnly', async () => {
504+
let onChange = jest.fn();
505+
let onSelectionChange = jest.fn();
506+
let {getByRole} = render(
507+
<TestComboBox
508+
isReadOnly
509+
value="4"
510+
inputValue="Finland"
511+
onChange={onChange}
512+
onSelectionChange={onSelectionChange}
513+
/>
514+
);
515+
516+
let input = getByRole('combobox');
517+
await user.click(input);
518+
await user.tab();
519+
520+
expect(onChange).not.toHaveBeenCalled();
521+
expect(onSelectionChange).not.toHaveBeenCalled();
522+
});
523+
503524
it('should support virtualizer', async () => {
504525
let items = [];
505526
for (let i = 0; i < 50; i++) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ export function useComboBoxState<T, M extends SelectionMode = 'single'>(
602602
open(null, 'focus');
603603
}
604604
} else {
605-
if (shouldCloseOnBlur) {
605+
if (shouldCloseOnBlur && !props.isReadOnly) {
606606
commitValue();
607607
}
608608

0 commit comments

Comments
 (0)