File tree Expand file tree Collapse file tree 4 files changed +13
-20
lines changed
packages/kit-headless/src/components/select Expand file tree Collapse file tree 4 files changed +13
-20
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export type SelectContext = {
14
14
listboxRef : Signal < HTMLUListElement | undefined > ;
15
15
groupRef : Signal < HTMLDivElement | undefined > ;
16
16
labelRef : Signal < HTMLDivElement | undefined > ;
17
- firstEnabledItemRef : Signal < HTMLLIElement | undefined > ;
17
+ highlightedItemRef : Signal < HTMLLIElement | undefined > ;
18
18
19
19
// core state
20
20
itemsMapSig : Readonly < Signal < TItemsMap > > ;
Original file line number Diff line number Diff line change @@ -35,7 +35,6 @@ export const HSelectItem = component$<SelectItemProps>((props) => {
35
35
const itemRef = useSignal < HTMLLIElement > ( ) ;
36
36
const localIndexSig = useSignal < number | null > ( null ) ;
37
37
const itemId = `${ context . localId } -${ _index } ` ;
38
- const isInitialFocusSig = useSignal < boolean > ( true ) ;
39
38
40
39
const { selectionManager$, getNextEnabledItemIndex$, getPrevEnabledItemIndex$ } =
41
40
useSelect ( ) ;
@@ -61,12 +60,6 @@ export const HSelectItem = component$<SelectItemProps>((props) => {
61
60
throw Error ( 'Qwik UI: Select component item cannot find its proper index.' ) ;
62
61
63
62
localIndexSig . value = _index ;
64
-
65
- // update the context with the first enabled item ref
66
- const firstEnabledIndex = await getNextEnabledItemIndex$ ( - 1 ) ;
67
- if ( localIndexSig . value === firstEnabledIndex ) {
68
- context . firstEnabledItemRef = itemRef ;
69
- }
70
63
} ) ;
71
64
72
65
useTask$ ( async function scrollableTask ( { track, cleanup } ) {
@@ -98,7 +91,10 @@ export const HSelectItem = component$<SelectItemProps>((props) => {
98
91
}
99
92
}
100
93
101
- if ( ! isInitialFocusSig . value ) return ;
94
+ // update the context with the highlighted item ref
95
+ if ( localIndexSig . value === context . highlightedIndexSig . value ) {
96
+ context . highlightedItemRef = itemRef ;
97
+ }
102
98
} ) ;
103
99
104
100
const handleClick$ = $ ( async ( ) => {
Original file line number Diff line number Diff line change @@ -161,7 +161,7 @@ export const HSelectImpl = component$<SelectProps<boolean> & InternalSelectProps
161
161
const currDisplayValueSig = useSignal < string | string [ ] > ( ) ;
162
162
163
163
const initialLoadSig = useSignal < boolean > ( true ) ;
164
- const firstEnabledItemRef = useSignal < HTMLLIElement > ( ) ;
164
+ const highlightedItemRef = useSignal < HTMLLIElement > ( ) ;
165
165
166
166
const context : SelectContext = {
167
167
itemsMapSig,
@@ -171,7 +171,7 @@ export const HSelectImpl = component$<SelectProps<boolean> & InternalSelectProps
171
171
listboxRef,
172
172
labelRef,
173
173
groupRef,
174
- firstEnabledItemRef ,
174
+ highlightedItemRef ,
175
175
localId,
176
176
highlightedIndexSig,
177
177
selectedIndexSetSig,
Original file line number Diff line number Diff line change @@ -100,16 +100,13 @@ export const HSelectTrigger = component$<SelectTriggerProps>((props) => {
100
100
101
101
/** When initially opening the listbox, we want to grab the first enabled option index */
102
102
if ( context . highlightedIndexSig . value === null ) {
103
- const firstItem = await getNextEnabledItemIndex$ ( - 1 ) ;
104
- context . highlightedIndexSig . value = firstItem ;
105
-
106
- // Wait for the popover code to be executed
107
- while ( ! ( context . firstEnabledItemRef . value === document . activeElement ) ) {
108
- await new Promise ( ( resolve ) => setTimeout ( resolve , 5 ) ) ;
109
- context . firstEnabledItemRef . value ?. focus ( ) ;
110
- }
103
+ context . highlightedIndexSig . value = await getNextEnabledItemIndex$ ( - 1 ) ;
104
+ }
111
105
112
- return ;
106
+ // Wait for the popover code to be executed
107
+ while ( context . highlightedItemRef . value !== document . activeElement ) {
108
+ await new Promise ( ( resolve ) => setTimeout ( resolve , 5 ) ) ;
109
+ context . highlightedItemRef . value ?. focus ( ) ;
113
110
}
114
111
} ) ;
115
112
You can’t perform that action at this time.
0 commit comments