Skip to content

Commit

Permalink
fix(dialog): prevent the close button from submitting forms (#2659)
Browse files Browse the repository at this point in the history
Prevents the `md-dialog-close` directive from submitting any forms that it is inside of.

Fixes #2599.
  • Loading branch information
crisbeto authored and mmalerba committed Jan 18, 2017
1 parent 737b608 commit 29f939a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/dialog/dialog-content-directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/lib/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

});
});

Expand Down

0 comments on commit 29f939a

Please sign in to comment.