Skip to content

Commit 40105e8

Browse files
committed
Address feedback
1 parent f8578df commit 40105e8

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

src/lib/dialog/dialog-container.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export class MatDialogContainer extends BasePortalOutlet {
7979
/** Element that was focused before the dialog was opened. Save this to restore upon close. */
8080
private _elementFocusedBeforeDialogWasOpened: HTMLElement | null = null;
8181

82-
/** Focus origin type that describes how the dialog got closed. */
83-
_closeFocusOrigin: FocusOrigin = 'program';
82+
/** Type of interaction that closed the dialog. */
83+
private _closeFocusOrigin: FocusOrigin = 'program';
8484

8585
/** The dialog configuration. */
8686
_config: MatDialogConfig;
@@ -187,8 +187,9 @@ export class MatDialogContainer extends BasePortalOutlet {
187187
}
188188

189189
/** Starts the dialog exit animation. */
190-
_startExitAnimation(): void {
190+
_startExitAnimation(focusOrigin: FocusOrigin): void {
191191
this._state = 'exit';
192+
this._closeFocusOrigin = focusOrigin;
192193

193194
// Mark the container for check so it can react if the
194195
// view container is using OnPush change detection.

src/lib/dialog/dialog-ref.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ export class MatDialogRef<T, R = any> {
7878

7979
/**
8080
* Close the dialog.
81-
* @param dialogResult Optional result to return to the dialog opener.
82-
* @param closeFocusOrigin Focus origin that describes how the dialog got closed
81+
* @param dialogResult Optional result to return to the dialog opener
82+
* @param focusOrigin Type of interaction that closed the dialog
8383
*/
84-
close(dialogResult?: R, closeFocusOrigin: FocusOrigin = 'program'): void {
84+
close(dialogResult?: R, focusOrigin: FocusOrigin = 'program'): void {
8585
this._result = dialogResult;
8686

8787
// Transition the backdrop in parallel to the dialog.
@@ -95,8 +95,7 @@ export class MatDialogRef<T, R = any> {
9595
this._overlayRef.detachBackdrop();
9696
});
9797

98-
this._containerInstance._closeFocusOrigin = closeFocusOrigin;
99-
this._containerInstance._startExitAnimation();
98+
this._containerInstance._startExitAnimation(focusOrigin);
10099
}
101100

102101
/**

src/lib/dialog/dialog.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {SpyLocation} from '@angular/common/testing';
2525
import {Directionality} from '@angular/cdk/bidi';
2626
import {MatDialogContainer} from './dialog-container';
2727
import {OverlayContainer, ScrollStrategy} from '@angular/cdk/overlay';
28-
import {A11yModule, FocusOrigin, FocusMonitor} from '@angular/cdk/a11y';
28+
import {FocusOrigin, FocusMonitor} from '@angular/cdk/a11y';
2929
import {A, ESCAPE} from '@angular/cdk/keycodes';
3030
import {dispatchKeyboardEvent} from '@angular/cdk/testing';
3131
import {
@@ -49,7 +49,7 @@ describe('MatDialog', () => {
4949

5050
beforeEach(fakeAsync(() => {
5151
TestBed.configureTestingModule({
52-
imports: [MatDialogModule, DialogTestModule, A11yModule],
52+
imports: [MatDialogModule, DialogTestModule],
5353
providers: [
5454
{provide: Location, useClass: SpyLocation}
5555
],
@@ -903,7 +903,7 @@ describe('MatDialog', () => {
903903
document.body.removeChild(button);
904904
}));
905905

906-
it('should re-focus the trigger via mouse when dialog closes through escape', fakeAsync(() => {
906+
it('should re-focus the trigger via keyboard when closed via escape key', fakeAsync(() => {
907907
const button = document.createElement('button');
908908
let lastFocusOrigin: FocusOrigin = null;
909909

@@ -932,7 +932,7 @@ describe('MatDialog', () => {
932932
document.body.removeChild(button);
933933
}));
934934

935-
it('should re-focus the trigger via keyboard when backdrop has been clicked', fakeAsync(() => {
935+
it('should re-focus the trigger via mouse when backdrop has been clicked', fakeAsync(() => {
936936
const button = document.createElement('button');
937937
let lastFocusOrigin: FocusOrigin = null;
938938

0 commit comments

Comments
 (0)