From 29f939ad3dd0702f1203429c7ee8574ea0ff6092 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Wed, 18 Jan 2017 06:22:36 +0100 Subject: [PATCH] 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. --- src/lib/dialog/dialog-content-directives.ts | 3 ++- src/lib/dialog/dialog.spec.ts | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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'); + }); + }); });