Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalerba committed Mar 15, 2024
1 parent b875350 commit a79e133
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/material/dialog/dialog-container.ts
Expand Up @@ -94,6 +94,8 @@ export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> impl
/** Current timer for dialog animations. */
private _animationTimer: ReturnType<typeof setTimeout> | null = null;

private _isDestroyed = false;

constructor(
elementRef: ElementRef,
focusTrapFactory: FocusTrapFactory,
Expand Down Expand Up @@ -262,6 +264,10 @@ export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> impl
* be called by sub-classes that use different animation implementations.
*/
protected _openAnimationDone(totalTime: number) {
if (this._isDestroyed) {
return;
}

if (this._config.delayFocusTrap) {
this._trapFocus();
}
Expand All @@ -275,6 +281,8 @@ export class MatDialogContainer extends CdkDialogContainer<MatDialogConfig> impl
if (this._animationTimer !== null) {
clearTimeout(this._animationTimer);
}

this._isDestroyed = true;
}

override attachComponentPortal<T>(portal: ComponentPortal<T>): ComponentRef<T> {
Expand Down
13 changes: 9 additions & 4 deletions src/material/dialog/dialog.spec.ts
Expand Up @@ -40,6 +40,7 @@ import {
inject,
TestBed,
tick,
waitForAsync,
} from '@angular/core/testing';
import {By} from '@angular/platform-browser';
import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations';
Expand Down Expand Up @@ -965,7 +966,8 @@ describe('MDC-based MatDialog', () => {
dialog.open(PizzaMsg, {disableClose: true, viewContainerRef: testViewContainerRef});

viewContainerFixture.detectChanges();
flushMicrotasks();
flush();
viewContainerFixture.detectChanges();

let backdrop = overlayContainerElement.querySelector('.cdk-overlay-backdrop') as HTMLElement;
let input = overlayContainerElement.querySelector('input') as HTMLInputElement;
Expand Down Expand Up @@ -994,7 +996,8 @@ describe('MDC-based MatDialog', () => {
});

viewContainerFixture.detectChanges();
flushMicrotasks();
flush();
viewContainerFixture.detectChanges();

let backdrop = overlayContainerElement.querySelector(
'.cdk-overlay-backdrop',
Expand Down Expand Up @@ -1179,7 +1182,8 @@ describe('MDC-based MatDialog', () => {
dialog.open(PizzaMsg, {viewContainerRef: testViewContainerRef});

viewContainerFixture.detectChanges();
flushMicrotasks();
flush();
viewContainerFixture.detectChanges();

expect(document.activeElement!.tagName)
.withContext('Expected first tabbable element (input) in the dialog to be focused.')
Expand Down Expand Up @@ -1505,7 +1509,8 @@ describe('MDC-based MatDialog', () => {
dialog.open(DialogWithoutFocusableElements);

viewContainerFixture.detectChanges();
flushMicrotasks();
flush();
viewContainerFixture.detectChanges();

expect(document.activeElement!.tagName)
.withContext('Expected dialog container to be focused.')
Expand Down

0 comments on commit a79e133

Please sign in to comment.