Skip to content

Commit e8c2832

Browse files
home and end keys
1 parent 1b548a8 commit e8c2832

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

packages/kit-headless/src/components/select/select-item.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import SelectContextId, {
1515
SelectItemContext,
1616
selectItemContextId,
1717
} from './select-context';
18-
import { useSelect } from './use-select';
18+
import { useSelect, useTypeahead } from './use-select';
1919

2020
export type SelectItemProps = PropsOf<'li'> & {
2121
/** Internal index we get from the inline component. Please see select-inline.tsx */
@@ -39,6 +39,8 @@ export const HSelectItem = component$<SelectItemProps>((props) => {
3939
const { selectionManager$, getNextEnabledItemIndex$, getPrevEnabledItemIndex$ } =
4040
useSelect();
4141

42+
const { typeahead$ } = useTypeahead();
43+
4244
const isSelectedSig = useComputed$(() => {
4345
const index = _index ?? null;
4446
return !disabled && context.selectedIndexSetSig.value.has(index!);
@@ -142,6 +144,8 @@ export const HSelectItem = component$<SelectItemProps>((props) => {
142144
});
143145

144146
const handleKeyDown$ = $(async (e: KeyboardEvent) => {
147+
typeahead$(e.key);
148+
145149
switch (e.key) {
146150
case 'ArrowDown':
147151
if (context.isListboxOpenSig.value) {

packages/kit-headless/src/components/select/select.test.ts

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -288,40 +288,34 @@ test.describe('Keyboard Behavior', () => {
288288
test(`GIVEN an open hero select
289289
WHEN pressing the end key
290290
THEN the last option should have data-highlighted`, async ({ page }) => {
291-
const {
292-
getTrigger,
293-
getItemAt: getOptionAt,
294-
openListbox,
295-
} = await setup(page, 'hero');
291+
const { driver: d } = await setup(page, 'hero');
296292

297-
await openListbox('click');
293+
await d.openListbox('click');
298294

299-
await getTrigger().focus();
300-
await getTrigger().press('End');
295+
await d.getItemAt(0).focus();
296+
await d.getItemAt(0).press('End');
301297

302-
await expect(getOptionAt('last')).toHaveAttribute('data-highlighted');
298+
await expect(d.getItemAt('last')).toHaveAttribute('data-highlighted');
303299
});
304300

305301
test(`GIVEN an open hero select
306302
WHEN pressing the home key after the end key
307303
THEN the first option should have data-highlighted`, async ({ page }) => {
308-
const {
309-
getTrigger,
310-
getItemAt: getOptionAt,
311-
openListbox,
312-
} = await setup(page, 'hero');
304+
const { driver: d } = await setup(page, 'hero');
313305

314-
await openListbox('click');
306+
await d.openListbox('click');
315307

316308
// to last index
317-
await getTrigger().focus();
318-
await getTrigger().press('End');
309+
await d.getItemAt(0).focus();
310+
await d.getItemAt(0).press('End');
319311

320-
await expect(getOptionAt('last')).toHaveAttribute('data-highlighted');
312+
await expect(d.getItemAt('last')).toHaveAttribute('data-highlighted');
321313

322314
// to first index
323-
await getTrigger().press('Home');
324-
await expect(getOptionAt(0)).toHaveAttribute('data-highlighted');
315+
const itemsLength = await d.getItemsLength();
316+
const lastItem = d.getItemAt(itemsLength - 1);
317+
await lastItem.press('Home');
318+
await expect(d.getItemAt(0)).toHaveAttribute('data-highlighted');
325319
});
326320

327321
test(`GIVEN an open hero select

0 commit comments

Comments
 (0)