Skip to content

Commit 9681b61

Browse files
fix: Ensure hovered (multi)select items aren't selected when typing space (#3902)
1 parent fb8953c commit 9681b61

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/multiselect/__integ__/multiselect.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@ describe(`Multiselect with filtering`, () => {
178178
})
179179
);
180180

181+
test(
182+
'does not select an option using space if it was "selected" via mouse hover',
183+
setupTest(async page => {
184+
await page.clickSelect();
185+
// Type in a filtering query that includes a space
186+
await page.keys('first');
187+
await page.hoverElement(wrapper.findDropdown()!.findOptions().get(2).toSelector());
188+
// space here should continue typing, not select
189+
await page.keys(' category');
190+
await expect(page.getSelectedOptionLabels()).resolves.toEqual([]);
191+
await expect(page.getValue(wrapper.findFilteringInput().findNativeInput().toSelector())).resolves.toBe(
192+
'first category'
193+
);
194+
})
195+
);
196+
181197
test(
182198
'keeps filtering state after selecting an option using keyboard',
183199
setupTest(async page => {

src/select/utils/use-select.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export function useSelect({
166166
closeDropdown();
167167
}
168168
},
169-
preventNativeSpace: !hasFilter || !!highlightedOption,
169+
preventNativeSpace: !hasFilter || (highlightedOption && highlightType.type === 'keyboard'),
170170
});
171171

172172
const triggerKeyDownHandler = useTriggerKeyboard({

0 commit comments

Comments
 (0)