@@ -13,8 +13,8 @@ import {
1313import { isBrowser } from '@builder.io/qwik/build' ;
1414import SelectContextId , { type SelectContext } from './select-context' ;
1515import { Opt } from './select-inline' ;
16- import { getActiveDescendant } from './utils' ;
1716import { HiddenSelect } from './hidden-select' ;
17+ import { useSelect } from './use-select' ;
1818
1919export type InternalSelectProps = {
2020 /** 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>(
8888 ...rest
8989 } = props ;
9090
91+ const { getActiveDescendant } = useSelect ( ) ;
92+
9193 // refs
9294 const rootRef = useSignal < HTMLDivElement > ( ) ;
9395 const triggerRef = useSignal < HTMLButtonElement > ( ) ;
@@ -148,6 +150,18 @@ export const SelectImpl = component$<SelectProps & InternalSelectProps>(
148150 }
149151 } ) ;
150152
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+
151165 const context : SelectContext = {
152166 triggerRef,
153167 popoverRef,
@@ -173,15 +187,7 @@ export const SelectImpl = component$<SelectProps & InternalSelectProps>(
173187 aria-controls = { listboxId }
174188 aria-expanded = { context . isListboxOpenSig . value }
175189 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 }
185191 { ...rest }
186192 >
187193 < Slot />
0 commit comments