From 326da0fc0dd974401dda0d571cf5524b4467d6e0 Mon Sep 17 00:00:00 2001 From: Roman Sandler Date: Fri, 17 Apr 2026 11:39:36 +0300 Subject: [PATCH] fix: preserve multi-select ComboBox selections for custom input --- .../test/ComboBox.test.js | 24 +++++++++++++++++++ .../src/combobox/useComboBoxState.ts | 12 +++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/react-aria-components/test/ComboBox.test.js b/packages/react-aria-components/test/ComboBox.test.js index af75cba5644..a6bc8bdd5ac 100644 --- a/packages/react-aria-components/test/ComboBox.test.js +++ b/packages/react-aria-components/test/ComboBox.test.js @@ -798,6 +798,30 @@ describe('ComboBox', () => { expect(comboboxTester.combobox).toHaveValue('Test'); }); + it.each(['{Escape}', '{Enter}', '{Tab}'])('should preserve multi-select value with custom input on %s', async (key) => { + let {container, queryByRole} = render( + + ); + let comboboxTester = testUtilUser.createTester('ComboBox', {root: container}); + let value = container.querySelector('.react-aria-ComboBoxValue'); + + expect(value).toHaveTextContent('Cat and Dog'); + + await user.tab(); + await user.keyboard('Den'); + expect(comboboxTester.combobox).toHaveValue('Den'); + + await user.keyboard(key); + + expect(queryByRole('listbox')).toBeNull(); + expect(comboboxTester.combobox).toHaveValue('Den'); + expect(value).toHaveTextContent('Cat and Dog'); + }); + it('should allow the user to deselect items with keyboard when multiselect (uncontrolled)', async () => { let onChange = jest.fn(); let {container} = render(); diff --git a/packages/react-stately/src/combobox/useComboBoxState.ts b/packages/react-stately/src/combobox/useComboBoxState.ts index 02f6bd0116c..28c04389591 100644 --- a/packages/react-stately/src/combobox/useComboBoxState.ts +++ b/packages/react-stately/src/combobox/useComboBoxState.ts @@ -147,8 +147,6 @@ export interface ComboBoxStateOptions ext shouldCloseOnBlur?: boolean } -const EMPTY_VALUE: Key[] = []; - /** * Provides state management for a combo box component. Handles building a collection * of items from props and manages the option selection state of the combo box. In addition, it tracks the input value, @@ -426,7 +424,15 @@ export function useComboBoxState