diff --git a/packages/@react-stately/combobox/src/useComboBoxState.ts b/packages/@react-stately/combobox/src/useComboBoxState.ts index a8a315ffb97..2ac35d3469b 100644 --- a/packages/@react-stately/combobox/src/useComboBoxState.ts +++ b/packages/@react-stately/combobox/src/useComboBoxState.ts @@ -306,26 +306,12 @@ export function useComboBoxState(props: ComboBoxStateOptions { - let proxy = new Proxy(selectionManager, { - get(target, prop, receiver) { - // If the menu is closed, don't update the selected key. - if (prop === 'replaceSelection' && !triggerState.isOpen) { - return () => {}; - } - return Reflect.get(target, prop, receiver); - } - }); - - return proxy; - }, [selectionManager, triggerState.isOpen]); - return { ...triggerState, toggle, open, close, - selectionManager: selectionManagerProxy, + selectionManager, selectedKey, setSelectedKey, disabledKeys, diff --git a/packages/@react-stately/combobox/test/useComboBoxState.test.js b/packages/@react-stately/combobox/test/useComboBoxState.test.js index 244f7afb36a..7c95620f87a 100644 --- a/packages/@react-stately/combobox/test/useComboBoxState.test.js +++ b/packages/@react-stately/combobox/test/useComboBoxState.test.js @@ -177,7 +177,6 @@ describe('useComboBoxState tests', function () { expect(result.current.selectionManager.selectedKeys).toContain('0'); expect(result.current.selectionManager.selectedKeys).not.toContain('1'); - act(() => {result.current.open();}); act(() => result.current.selectionManager.replaceSelection('1')); expect(result.current.selectionManager.selectedKeys).toContain('0'); expect(result.current.selectionManager.selectedKeys).not.toContain('1'); @@ -191,34 +190,22 @@ describe('useComboBoxState tests', function () { expect(result.current.selectionManager.selectedKeys).toContain('0'); expect(result.current.selectionManager.selectedKeys).not.toContain('1'); - act(() => {result.current.open();}); act(() => result.current.selectionManager.replaceSelection('1')); expect(result.current.selectionManager.selectedKeys).toContain('1'); expect(result.current.selectionManager.selectedKeys).not.toContain('0'); expect(onSelectionChange).toHaveBeenCalledWith('1'); }); - it('supports default no selection', function () { + it('supports sdefault no selection', function () { let initialProps = {...defaultProps}; let {result} = renderHook((props) => useComboBoxState(props), {initialProps}); expect(result.current.selectionManager.selectionMode).toBe('single'); expect(result.current.selectionManager.selectedKeys.size).toBe(0); - act(() => {result.current.open();}); act(() => result.current.selectionManager.replaceSelection('1')); expect(result.current.selectionManager.selectedKeys).toContain('1'); expect(result.current.selectionManager.selectedKeys).not.toContain('0'); expect(onSelectionChange).toHaveBeenCalledWith('1'); }); - - it('won\'t perform replace a selection if the combobox is closed', function () { - // This case covers if a option in the menu is clicked while the menu is closing - let initialProps = {...defaultProps}; - let {result} = renderHook((props) => useComboBoxState(props), {initialProps}); - - act(() => result.current.selectionManager.replaceSelection('1')); - expect(result.current.selectionManager.selectedKeys.size).toEqual(0); - expect(onSelectionChange).toHaveBeenCalledTimes(0); - }); }); });