From 3b2445bcb6f0abcfc4edbffd0cb2a6ab25c35a2e Mon Sep 17 00:00:00 2001 From: Slava Dodonov Date: Sun, 5 Jul 2026 03:14:54 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20Select=20typeahead=20no?= =?UTF-8?q?=20longer=20skips=20options=20with=20falsy=20val?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/select-falsy-typeahead.md | 7 +++++ packages/ui/src/Select/Select.tsx | 4 +-- .../Select/__tests__/Select.browser.test.tsx | 26 +++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 .changeset/select-falsy-typeahead.md diff --git a/.changeset/select-falsy-typeahead.md b/.changeset/select-falsy-typeahead.md new file mode 100644 index 00000000..52628a9f --- /dev/null +++ b/.changeset/select-falsy-typeahead.md @@ -0,0 +1,7 @@ +--- +"@vega-ui/react": patch +--- + +Fix Select typeahead skipping options with falsy values + +`onMatch` (typeahead selection while the listbox is closed) guarded the matched value with `if (!value) return`, so options whose value is `0` or an empty string could be highlighted but never actually selected — common with numeric IDs. The guard now checks for `undefined` (a missing map entry) only. Covered with a regression test that selects a `value={0}` option by typing. diff --git a/packages/ui/src/Select/Select.tsx b/packages/ui/src/Select/Select.tsx index fb3364b4..6311be74 100644 --- a/packages/ui/src/Select/Select.tsx +++ b/packages/ui/src/Select/Select.tsx @@ -166,8 +166,8 @@ export const Select = ({ setSelectedIndex(index) const value = indexValueMap.get(index) - if (!value) return - + if (value === undefined) return + select(value) } diff --git a/packages/ui/src/Select/__tests__/Select.browser.test.tsx b/packages/ui/src/Select/__tests__/Select.browser.test.tsx index 70e4f3aa..c2810759 100644 --- a/packages/ui/src/Select/__tests__/Select.browser.test.tsx +++ b/packages/ui/src/Select/__tests__/Select.browser.test.tsx @@ -388,6 +388,32 @@ describe('Select', () => { }); }); + it('selects an option with a falsy value (0) by typing', async () => { + const onSelectValue = vi.fn(); + + const r2 = render( + , + ); + + (r2.getByTestId('combobox-numeric') as HTMLElement).focus(); + await userEvent.keyboard('zer'); + + await waitFor(() => { + expect(onSelectValue).toHaveBeenCalledWith(0); + }); + }); + it('does not auto-select while open (typing only searches)', async () => { const onSelectValue = vi.fn(); r.rerender();