99 TemplateRef ,
1010 ViewContainerRef ,
1111 HostListener ,
12- OnChanges
12+ OnChanges ,
13+ HostBinding
1314} from "@angular/core" ;
1415import { fromEvent } from "rxjs" ;
1516import { DialogService } from "./dialog.service" ;
@@ -94,6 +95,9 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
9495 @Output ( ) onClose : EventEmitter < any > = new EventEmitter < any > ( ) ;
9596 dialogConfig : DialogConfig ;
9697
98+ @HostBinding ( "attr.role" ) role = "button" ;
99+ @HostBinding ( "attr.aria-expanded" ) expanded = false ;
100+
97101 /**
98102 * Creates an instance of DialogDirective.
99103 * @param {ElementRef } elementRef
@@ -158,7 +162,7 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
158162 this . dialogService . isClosed . subscribe ( value => {
159163 if ( value ) {
160164 this . onClose . emit ( ) ;
161- this . elementRef . nativeElement . setAttribute ( "aria- expanded" , " false" ) ;
165+ this . expanded = false ;
162166 }
163167 } ) ;
164168
@@ -182,7 +186,7 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
182186 */
183187 open ( ) {
184188 this . dialogService . open ( this . viewContainerRef , this . dialogConfig ) ;
185- this . elementRef . nativeElement . setAttribute ( "aria- expanded" , " true" ) ;
189+ this . expanded = true ;
186190 }
187191
188192 /**
@@ -192,7 +196,7 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
192196 */
193197 toggle ( ) {
194198 this . dialogService . toggle ( this . viewContainerRef , this . dialogConfig ) ;
195- this . elementRef . nativeElement . setAttribute ( "aria- expanded" , this . dialogService . isOpen ) ;
199+ this . expanded = this . dialogService . isOpen ;
196200 }
197201
198202 /**
@@ -202,7 +206,7 @@ export class DialogDirective implements OnInit, OnDestroy, OnChanges {
202206 */
203207 close ( ) {
204208 this . dialogService . close ( this . viewContainerRef ) ;
205- this . elementRef . nativeElement . setAttribute ( "aria- expanded" , " false" ) ;
209+ this . expanded = false ;
206210 }
207211
208212 /**
0 commit comments