@@ -13,8 +13,8 @@ import {
13
13
import { isBrowser } from '@builder.io/qwik/build' ;
14
14
import SelectContextId , { type SelectContext } from './select-context' ;
15
15
import { Opt } from './select-inline' ;
16
- import { getActiveDescendant } from './utils' ;
17
16
import { HiddenSelect } from './hidden-select' ;
17
+ import { useSelect } from './use-select' ;
18
18
19
19
export type InternalSelectProps = {
20
20
/** Our source of truth for the options. We get this at pre-render time in the inline component, that way we do not need to call native methods such as textContent.
@@ -88,6 +88,8 @@ export const SelectImpl = component$<SelectProps & InternalSelectProps>(
88
88
...rest
89
89
} = props ;
90
90
91
+ const { getActiveDescendant } = useSelect ( ) ;
92
+
91
93
// refs
92
94
const rootRef = useSignal < HTMLDivElement > ( ) ;
93
95
const triggerRef = useSignal < HTMLButtonElement > ( ) ;
@@ -148,6 +150,18 @@ export const SelectImpl = component$<SelectProps & InternalSelectProps>(
148
150
}
149
151
} ) ;
150
152
153
+ const activeDescendantSig = useComputed$ ( ( ) => {
154
+ if ( isListboxOpenSig . value ) {
155
+ return getActiveDescendant (
156
+ highlightedIndexSig . value ?? - 1 ,
157
+ optionsSig . value ,
158
+ localId ,
159
+ ) ;
160
+ } else {
161
+ return '' ;
162
+ }
163
+ } ) ;
164
+
151
165
const context : SelectContext = {
152
166
triggerRef,
153
167
popoverRef,
@@ -173,15 +187,7 @@ export const SelectImpl = component$<SelectProps & InternalSelectProps>(
173
187
aria-controls = { listboxId }
174
188
aria-expanded = { context . isListboxOpenSig . value }
175
189
aria-haspopup = "listbox"
176
- aria-activedescendant = {
177
- context . isListboxOpenSig . value
178
- ? getActiveDescendant (
179
- context . highlightedIndexSig . value ?? - 1 ,
180
- context . optionsSig . value ,
181
- context . localId ,
182
- )
183
- : ''
184
- }
190
+ aria-activedescendant = { activeDescendantSig . value }
185
191
{ ...rest }
186
192
>
187
193
< Slot />
0 commit comments