Skip to content

Commit f3de960

Browse files
Revert "Prevent ComboBox item selection if menu is closing (#3999)" (#4057)
This reverts commit 8c61397. Co-authored-by: Robert Snow <[email protected]>
1 parent f5c005b commit f3de960

File tree

2 files changed

+2
-29
lines changed

2 files changed

+2
-29
lines changed

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -306,26 +306,12 @@ export function useComboBoxState<T extends object>(props: ComboBoxStateOptions<T
306306
setFocusedState(isFocused);
307307
};
308308

309-
let selectionManagerProxy = useMemo(() => {
310-
let proxy = new Proxy(selectionManager, {
311-
get(target, prop, receiver) {
312-
// If the menu is closed, don't update the selected key.
313-
if (prop === 'replaceSelection' && !triggerState.isOpen) {
314-
return () => {};
315-
}
316-
return Reflect.get(target, prop, receiver);
317-
}
318-
});
319-
320-
return proxy;
321-
}, [selectionManager, triggerState.isOpen]);
322-
323309
return {
324310
...triggerState,
325311
toggle,
326312
open,
327313
close,
328-
selectionManager: selectionManagerProxy,
314+
selectionManager,
329315
selectedKey,
330316
setSelectedKey,
331317
disabledKeys,

packages/@react-stately/combobox/test/useComboBoxState.test.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ describe('useComboBoxState tests', function () {
177177
expect(result.current.selectionManager.selectedKeys).toContain('0');
178178
expect(result.current.selectionManager.selectedKeys).not.toContain('1');
179179

180-
act(() => {result.current.open();});
181180
act(() => result.current.selectionManager.replaceSelection('1'));
182181
expect(result.current.selectionManager.selectedKeys).toContain('0');
183182
expect(result.current.selectionManager.selectedKeys).not.toContain('1');
@@ -191,34 +190,22 @@ describe('useComboBoxState tests', function () {
191190
expect(result.current.selectionManager.selectedKeys).toContain('0');
192191
expect(result.current.selectionManager.selectedKeys).not.toContain('1');
193192

194-
act(() => {result.current.open();});
195193
act(() => result.current.selectionManager.replaceSelection('1'));
196194
expect(result.current.selectionManager.selectedKeys).toContain('1');
197195
expect(result.current.selectionManager.selectedKeys).not.toContain('0');
198196
expect(onSelectionChange).toHaveBeenCalledWith('1');
199197
});
200198

201-
it('supports default no selection', function () {
199+
it('supports sdefault no selection', function () {
202200
let initialProps = {...defaultProps};
203201
let {result} = renderHook((props) => useComboBoxState(props), {initialProps});
204202
expect(result.current.selectionManager.selectionMode).toBe('single');
205203
expect(result.current.selectionManager.selectedKeys.size).toBe(0);
206204

207-
act(() => {result.current.open();});
208205
act(() => result.current.selectionManager.replaceSelection('1'));
209206
expect(result.current.selectionManager.selectedKeys).toContain('1');
210207
expect(result.current.selectionManager.selectedKeys).not.toContain('0');
211208
expect(onSelectionChange).toHaveBeenCalledWith('1');
212209
});
213-
214-
it('won\'t perform replace a selection if the combobox is closed', function () {
215-
// This case covers if a option in the menu is clicked while the menu is closing
216-
let initialProps = {...defaultProps};
217-
let {result} = renderHook((props) => useComboBoxState(props), {initialProps});
218-
219-
act(() => result.current.selectionManager.replaceSelection('1'));
220-
expect(result.current.selectionManager.selectedKeys.size).toEqual(0);
221-
expect(onSelectionChange).toHaveBeenCalledTimes(0);
222-
});
223210
});
224211
});

0 commit comments

Comments
 (0)