diff --git a/src/lib/dialog/dialog-content-directives.ts b/src/lib/dialog/dialog-content-directives.ts index a7c8e3875ef1..5f268182511b 100644 --- a/src/lib/dialog/dialog-content-directives.ts +++ b/src/lib/dialog/dialog-content-directives.ts @@ -9,7 +9,8 @@ import {MdDialogRef} from './dialog-ref'; selector: 'button[md-dialog-close], button[mat-dialog-close]', host: { '(click)': 'dialogRef.close()', - '[attr.aria-label]': 'ariaLabel' + '[attr.aria-label]': 'ariaLabel', + 'type': 'button', // Prevents accidental form submits. } }) export class MdDialogClose { diff --git a/src/lib/dialog/dialog.spec.ts b/src/lib/dialog/dialog.spec.ts index 38243742b63c..6c81e45b682e 100644 --- a/src/lib/dialog/dialog.spec.ts +++ b/src/lib/dialog/dialog.spec.ts @@ -343,6 +343,12 @@ describe('MdDialog', () => { expect(button.getAttribute('aria-label')).toBe('Best close button ever'); }); + it('should override the "type" attribute of the close button', () => { + let button = overlayContainerElement.querySelector('button[md-dialog-close]'); + + expect(button.getAttribute('type')).toBe('button'); + }); + }); });