mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(datepicker): calendar toggle submitting parent form (#4531)
Prevents the toggle for the datepicker's calendar from submitting its parent form. Fixes #4530.
This commit is contained in:
committed by
Jeremy Elbourn
parent
58c252f36e
commit
84ea8b2185
@@ -9,6 +9,7 @@ import {MdDatepickerIntl} from './datepicker-intl';
|
||||
template: '',
|
||||
styleUrls: ['datepicker-toggle.css'],
|
||||
host: {
|
||||
'[attr.type]': 'type',
|
||||
'[class.mat-datepicker-toggle]': 'true',
|
||||
'[attr.aria-label]': '_intl.openCalendarLabel',
|
||||
'(click)': '_open($event)',
|
||||
@@ -17,8 +18,12 @@ import {MdDatepickerIntl} from './datepicker-intl';
|
||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||
})
|
||||
export class MdDatepickerToggle<D> {
|
||||
/** Datepicker instance that the button will toggle. */
|
||||
@Input('mdDatepickerToggle') datepicker: MdDatepicker<D>;
|
||||
|
||||
/** Type of the button. */
|
||||
@Input() type: string = 'button';
|
||||
|
||||
@Input('matDatepickerToggle')
|
||||
get _datepicker() { return this.datepicker; }
|
||||
set _datepicker(v: MdDatepicker<D>) { this.datepicker = v; }
|
||||
|
||||
@@ -374,7 +374,7 @@ describe('MdDatepicker', () => {
|
||||
fixture.detectChanges();
|
||||
}));
|
||||
|
||||
it('should open calendar when toggle clicked', async(() => {
|
||||
it('should open calendar when toggle clicked', () => {
|
||||
expect(document.querySelector('md-dialog-container')).toBeNull();
|
||||
|
||||
let toggle = fixture.debugElement.query(By.css('button'));
|
||||
@@ -382,7 +382,12 @@ describe('MdDatepicker', () => {
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(document.querySelector('md-dialog-container')).not.toBeNull();
|
||||
}));
|
||||
});
|
||||
|
||||
it('should set the `button` type on the trigger to prevent form submissions', () => {
|
||||
let toggle = fixture.debugElement.query(By.css('button')).nativeElement;
|
||||
expect(toggle.getAttribute('type')).toBe('button');
|
||||
});
|
||||
});
|
||||
|
||||
describe('datepicker inside input-container', () => {
|
||||
|
||||
Reference in New Issue
Block a user