Skip to content

Commit 29f939a

Browse files
crisbetommalerba
authored andcommitted
fix(dialog): prevent the close button from submitting forms (#2659)
Prevents the `md-dialog-close` directive from submitting any forms that it is inside of. Fixes #2599.
1 parent 737b608 commit 29f939a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/lib/dialog/dialog-content-directives.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import {MdDialogRef} from './dialog-ref';
99
selector: 'button[md-dialog-close], button[mat-dialog-close]',
1010
host: {
1111
'(click)': 'dialogRef.close()',
12-
'[attr.aria-label]': 'ariaLabel'
12+
'[attr.aria-label]': 'ariaLabel',
13+
'type': 'button', // Prevents accidental form submits.
1314
}
1415
})
1516
export class MdDialogClose {

src/lib/dialog/dialog.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,12 @@ describe('MdDialog', () => {
343343
expect(button.getAttribute('aria-label')).toBe('Best close button ever');
344344
});
345345

346+
it('should override the "type" attribute of the close button', () => {
347+
let button = overlayContainerElement.querySelector('button[md-dialog-close]');
348+
349+
expect(button.getAttribute('type')).toBe('button');
350+
});
351+
346352
});
347353
});
348354

0 commit comments

Comments
 (0)