Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/material/dialog/dialog-content-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ export class MatDialogClose implements OnInit, OnChanges {
}

_onButtonClick(event: MouseEvent) {
// For compatibility with `disabledInteractive`. We don't need to handle plain `disabled`,
// because disabled buttons don't dispatch click events by default. See #33366.
if (this._elementRef.nativeElement.getAttribute('aria-disabled') === 'true') {
return;
}

// Determinate the focus origin using the click event, because using the FocusMonitor will
// result in incorrect origins. Most of the time, close buttons will be auto focused in the
// dialog, and therefore clicking the button won't result in a focus change. This means that
Expand Down
19 changes: 19 additions & 0 deletions src/material/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,25 @@ describe('MatDialog', () => {
);
});

it('should not close when clicking on an aria-disabled close button', async () => {
expect(overlayContainerElement.querySelectorAll('.mat-mdc-dialog-container').length).toBe(
1,
);

const closeButton = overlayContainerElement.querySelector(
'button[mat-dialog-close]',
) as HTMLElement;

closeButton.setAttribute('aria-disabled', 'true');
closeButton.click();
viewContainerFixture.detectChanges();
await viewContainerFixture.whenStable();

expect(overlayContainerElement.querySelectorAll('.mat-mdc-dialog-container').length).toBe(
1,
);
});

it('should not close if [mat-dialog-close] is applied on a non-button node', () => {
expect(overlayContainerElement.querySelectorAll('.mat-mdc-dialog-container').length).toBe(
1,
Expand Down
Loading