Skip to content

Commit e0ce73b

Browse files
feat(select): expected index behavior from next option
1 parent 4b0f720 commit e0ce73b

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const SelectTrigger = component$<SelectTriggerProps>((props) => {
1313
const context = useContext(SelectContextId);
1414
const openKeys = ['ArrowUp', 'ArrowDown'];
1515
const closedKeys = [`Escape`];
16-
const initialIndex = context.highlightedIndexSig.value === -1;
16+
// const initialIndex = context.highlightedIndexSig.value === -1;
1717

1818
// Both the space and enter keys run with handleClick$
1919
const handleClick$ = $(() => {
@@ -49,17 +49,20 @@ export const SelectTrigger = component$<SelectTriggerProps>((props) => {
4949
context.isListboxOpenSig.value = false;
5050
}
5151

52-
if (initialIndex) {
53-
context.highlightedIndexSig.value++;
54-
return;
55-
}
56-
5752
if (e.key === 'Home') {
5853
context.highlightedIndexSig.value = 0;
54+
console.log('Highlighted index: ', context.highlightedIndexSig.value);
55+
return;
5956
}
6057

6158
if (e.key === 'End') {
6259
context.highlightedIndexSig.value = context.optionRefsArray.value.length - 1;
60+
return;
61+
}
62+
63+
if (context.highlightedIndexSig.value === -1) {
64+
context.highlightedIndexSig.value++;
65+
return;
6366
}
6467

6568
if (context.isListboxOpenSig.value) {

0 commit comments

Comments
 (0)