@@ -140,6 +140,17 @@ export interface ComboboxControllerOptions<Item extends HTMLElement> extends
140140 * By default, toggles the `hidden` attribute on the item
141141 */
142142 setItemHidden ?( item : Item , hidden : boolean ) : void ;
143+ /**
144+ * Optional. When provided, passed to ListboxController so it does not set
145+ * aria-setsize/aria-posinset on items.
146+ */
147+ setItems ?( items : Item [ ] ) : void ;
148+ /**
149+ * Optional. Returns position-in-set and set size for the focused item when
150+ * building the Safari VoiceOver live-region announcement ("N of M").
151+ * When not provided, the controller reads aria-posinset/aria-setsize from the item.
152+ */
153+ getItemPosition ?( item : Item , items : Item [ ] ) : { posInSet : number ; setSize : number } | null ;
143154}
144155
145156/**
@@ -352,6 +363,7 @@ export class ComboboxController<
352363 getATFocusedItem : ( ) => this . items [ this . #fc?. atFocusedItemIndex ?? - 1 ] ?? null ,
353364 isItemDisabled : this . options . isItemDisabled ,
354365 setItemSelected : this . options . setItemSelected ,
366+ setItems : this . options . setItems ,
355367 } ) ;
356368 ComboboxController . instances . set ( host , this ) ;
357369 ComboboxController . hosts . add ( host ) ;
@@ -551,11 +563,21 @@ export class ComboboxController<
551563 if ( this . #lb. isSelected ( item ) ) {
552564 text += `, (${ this . #translate( 'selected' , langKey ) } )` ;
553565 }
554- if ( item . hasAttribute ( 'aria-setsize' ) && item . hasAttribute ( 'aria-posinset' ) ) {
566+ const position =
567+ typeof this . options . getItemPosition === 'function' ?
568+ this . options . getItemPosition ( item , this . items )
569+ : null ;
570+ const posInSet =
571+ position ?. posInSet
572+ ?? ( item . hasAttribute ( 'aria-posinset' ) ? item . getAttribute ( 'aria-posinset' ) : null ) ;
573+ const setSize =
574+ position ?. setSize
575+ ?? ( item . hasAttribute ( 'aria-setsize' ) ? item . getAttribute ( 'aria-setsize' ) : null ) ;
576+ if ( posInSet != null && setSize != null ) {
555577 if ( langKey === 'ja' ) {
556- text += `, (${ item . getAttribute ( 'aria-setsize' ) } 件中 ${ item . getAttribute ( 'aria-posinset' ) } 件目)` ;
578+ text += `, (${ setSize } 件中 ${ posInSet } 件目)` ;
557579 } else {
558- text += `, (${ item . getAttribute ( 'aria-posinset' ) } ${ this . #translate( 'of' , langKey ) } ${ item . getAttribute ( 'aria-setsize' ) } )` ;
580+ text += `, (${ posInSet } ${ this . #translate( 'of' , langKey ) } ${ setSize } )` ;
559581 }
560582 }
561583 ComboboxController . #alert. lang = lang ;
0 commit comments