@@ -618,6 +618,34 @@ describe('MdDialog', () => {
618618 . toBe ( 'INPUT' , 'Expected first tabbable element (input) in the dialog to be focused.' ) ;
619619 } ) ) ;
620620
621+ it ( 'should be able to specify what element should be focused on open' , fakeAsync ( ( ) => {
622+ dialog . open ( PizzaMsg , { focusOnOpen : 'button' } ) ;
623+
624+ viewContainerFixture . detectChanges ( ) ;
625+ flushMicrotasks ( ) ;
626+
627+ expect ( document . activeElement . tagName ) . toBe ( 'BUTTON' ) ;
628+ } ) ) ;
629+
630+ it ( 'should fall back to the first focusable element, if the override is not found' ,
631+ fakeAsync ( ( ) => {
632+ dialog . open ( PizzaMsg , { focusOnOpen : 'unicorn' } ) ;
633+
634+ viewContainerFixture . detectChanges ( ) ;
635+ flushMicrotasks ( ) ;
636+
637+ expect ( document . activeElement . tagName ) . toBe ( 'INPUT' ) ;
638+ } ) ) ;
639+
640+ it ( 'should be able to focus the dialog container' , fakeAsync ( ( ) => {
641+ dialog . open ( PizzaMsg , { focusOnOpen : '[role="dialog"]' } ) ;
642+
643+ viewContainerFixture . detectChanges ( ) ;
644+ flushMicrotasks ( ) ;
645+
646+ expect ( document . activeElement . tagName ) . toBe ( 'MD-DIALOG-CONTAINER' ) ;
647+ } ) ) ;
648+
621649 it ( 'should re-focus trigger element when dialog closes' , fakeAsync ( ( ) => {
622650 // Create a element that has focus before the dialog is opened.
623651 let button = document . createElement ( 'button' ) ;
@@ -749,6 +777,32 @@ describe('MdDialog', () => {
749777 } ) ) ;
750778
751779 } ) ;
780+
781+ describe ( 'aria-label' , ( ) => {
782+ it ( 'should be able to set a custom aria-label' , ( ) => {
783+ dialog . open ( PizzaMsg , {
784+ ariaLabel : 'Hello there' ,
785+ viewContainerRef : testViewContainerRef
786+ } ) ;
787+ viewContainerFixture . detectChanges ( ) ;
788+
789+ const container = overlayContainerElement . querySelector ( 'md-dialog-container' ) ! ;
790+ expect ( container . getAttribute ( 'aria-label' ) ) . toBe ( 'Hello there' ) ;
791+ } ) ;
792+
793+ it ( 'should not set the aria-labelledby automatically if it has an aria-label' , fakeAsync ( ( ) => {
794+ dialog . open ( ContentElementDialog , {
795+ ariaLabel : 'Hello there' ,
796+ viewContainerRef : testViewContainerRef
797+ } ) ;
798+ viewContainerFixture . detectChanges ( ) ;
799+ tick ( ) ;
800+ viewContainerFixture . detectChanges ( ) ;
801+
802+ const container = overlayContainerElement . querySelector ( 'md-dialog-container' ) ! ;
803+ expect ( container . hasAttribute ( 'aria-labelledby' ) ) . toBe ( false ) ;
804+ } ) ) ;
805+ } ) ;
752806} ) ;
753807
754808describe ( 'MdDialog with a parent MdDialog' , ( ) => {
0 commit comments