66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import {
10- _IdGenerator ,
11- ActiveDescendantKeyManager ,
12- addAriaReferencedId ,
13- LiveAnnouncer ,
14- removeAriaReferencedId ,
15- } from '@angular/cdk/a11y' ;
9+ import { _IdGenerator , ActiveDescendantKeyManager , LiveAnnouncer } from '@angular/cdk/a11y' ;
1610import { Directionality } from '@angular/cdk/bidi' ;
1711import { SelectionModel } from '@angular/cdk/collections' ;
1812import {
@@ -720,7 +714,6 @@ export class MatSelect
720714 this . _destroy . next ( ) ;
721715 this . _destroy . complete ( ) ;
722716 this . stateChanges . complete ( ) ;
723- this . _clearFromModal ( ) ;
724717 }
725718
726719 /** Toggles the overlay panel open or closed. */
@@ -743,7 +736,6 @@ export class MatSelect
743736
744737 this . _cleanupDetach ?.( ) ;
745738 this . _overlayWidth = this . _getOverlayWidth ( this . _preferredOverlayOrigin ) ;
746- this . _applyModalPanelOwnership ( ) ;
747739 this . _panelOpen = true ;
748740 this . _overlayDir . positionChange . pipe ( take ( 1 ) ) . subscribe ( ( ) => {
749741 this . _changeDetectorRef . detectChanges ( ) ;
@@ -761,71 +753,6 @@ export class MatSelect
761753 Promise . resolve ( ) . then ( ( ) => this . openedChange . emit ( true ) ) ;
762754 }
763755
764- /**
765- * Track which modal we have modified the `aria-owns` attribute of. When the combobox trigger is
766- * inside an aria-modal, we apply aria-owns to the parent modal with the `id` of the options
767- * panel. Track the modal we have changed so we can undo the changes on destroy.
768- */
769- private _trackedModal : Element | null = null ;
770-
771- /**
772- * If the autocomplete trigger is inside of an `aria-modal` element, connect
773- * that modal to the options panel with `aria-owns`.
774- *
775- * For some browser + screen reader combinations, when navigation is inside
776- * of an `aria-modal` element, the screen reader treats everything outside
777- * of that modal as hidden or invisible.
778- *
779- * This causes a problem when the combobox trigger is _inside_ of a modal, because the
780- * options panel is rendered _outside_ of that modal, preventing screen reader navigation
781- * from reaching the panel.
782- *
783- * We can work around this issue by applying `aria-owns` to the modal with the `id` of
784- * the options panel. This effectively communicates to assistive technology that the
785- * options panel is part of the same interaction as the modal.
786- *
787- * At time of this writing, this issue is present in VoiceOver.
788- * See https://github.com/angular/components/issues/20694
789- */
790- private _applyModalPanelOwnership ( ) {
791- // TODO(http://github.com/angular/components/issues/26853): consider de-duplicating this with
792- // the `LiveAnnouncer` and any other usages.
793- //
794- // Note that the selector here is limited to CDK overlays at the moment in order to reduce the
795- // section of the DOM we need to look through. This should cover all the cases we support, but
796- // the selector can be expanded if it turns out to be too narrow.
797- const modal = this . _elementRef . nativeElement . closest (
798- 'body > .cdk-overlay-container [aria-modal="true"]' ,
799- ) ;
800-
801- if ( ! modal ) {
802- // Most commonly, the autocomplete trigger is not inside a modal.
803- return ;
804- }
805-
806- const panelId = `${ this . id } -panel` ;
807-
808- if ( this . _trackedModal ) {
809- removeAriaReferencedId ( this . _trackedModal , 'aria-owns' , panelId ) ;
810- }
811-
812- addAriaReferencedId ( modal , 'aria-owns' , panelId ) ;
813- this . _trackedModal = modal ;
814- }
815-
816- /** Clears the reference to the listbox overlay element from the modal it was added to. */
817- private _clearFromModal ( ) {
818- if ( ! this . _trackedModal ) {
819- // Most commonly, the autocomplete trigger is not used inside a modal.
820- return ;
821- }
822-
823- const panelId = `${ this . id } -panel` ;
824-
825- removeAriaReferencedId ( this . _trackedModal , 'aria-owns' , panelId ) ;
826- this . _trackedModal = null ;
827- }
828-
829756 /** Closes the overlay panel and focuses the host element. */
830757 close ( ) : void {
831758 if ( this . _panelOpen ) {
0 commit comments