-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(datepicker): close calendar after choose the same date again #6323
Changes from 5 commits
9034f7c
c839ac6
64301f0
b3cec45
878e109
0ae408d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -190,6 +190,30 @@ describe('MdDatepicker', () => { | |
}); | ||
}); | ||
|
||
it('clicking the currently selected date should close the calendar' + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: space before close of string so result doesn't read: "calendarwithout" |
||
'without firing selectedChanged', () => { | ||
const selectedChangedSpy = | ||
spyOn(testComponent.datepicker.selectedChanged, 'emit').and.callThrough(); | ||
for (let changeCount = 1; changeCount < 3; changeCount++) { | ||
const currentDay = changeCount; | ||
testComponent.datepicker.open(); | ||
fixture.detectChanges(); | ||
|
||
expect(document.querySelector('md-datepicker-content')).not.toBeNull(); | ||
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, currentDay)); | ||
|
||
let cells = document.querySelectorAll('.mat-calendar-body-cell'); | ||
dispatchMouseEvent(cells[1], 'click'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. verify that |
||
fixture.detectChanges(); | ||
} | ||
|
||
fixture.whenStable().then(() => { | ||
expect(selectedChangedSpy.calls.count()).toEqual(1); | ||
expect(document.querySelector('md-dialog-container')).toBeNull(); | ||
expect(testComponent.datepickerInput.value).toEqual(new Date(2020, JAN, 2)); | ||
}); | ||
}); | ||
|
||
it('startAt should fallback to input value', () => { | ||
expect(testComponent.datepicker.startAt).toEqual(new Date(2020, JAN, 1)); | ||
}); | ||
|
@@ -362,7 +386,7 @@ describe('MdDatepicker', () => { | |
expect(testComponent.datepickerInput.value).toBeNull(); | ||
|
||
let selected = new Date(2017, JAN, 1); | ||
testComponent.datepicker._selectAndClose(selected); | ||
testComponent.datepicker._select(selected); | ||
fixture.detectChanges(); | ||
|
||
fixture.whenStable().then(() => { | ||
|
@@ -389,7 +413,7 @@ describe('MdDatepicker', () => { | |
|
||
expect(inputEl.classList).toContain('ng-pristine'); | ||
|
||
testComponent.datepicker._selectAndClose(new Date(2017, JAN, 1)); | ||
testComponent.datepicker._select(new Date(2017, JAN, 1)); | ||
fixture.detectChanges(); | ||
|
||
fixture.whenStable().then(() => { | ||
|
@@ -435,7 +459,7 @@ describe('MdDatepicker', () => { | |
|
||
expect(inputEl.classList).toContain('ng-untouched'); | ||
|
||
testComponent.datepicker._selectAndClose(new Date(2017, JAN, 1)); | ||
testComponent.datepicker._select(new Date(2017, JAN, 1)); | ||
fixture.detectChanges(); | ||
|
||
fixture.whenStable().then(() => { | ||
|
@@ -479,7 +503,7 @@ describe('MdDatepicker', () => { | |
expect(testComponent.datepickerInput.value).toBeNull(); | ||
|
||
let selected = new Date(2017, JAN, 1); | ||
testComponent.datepicker._selectAndClose(selected); | ||
testComponent.datepicker._select(selected); | ||
fixture.detectChanges(); | ||
|
||
expect(testComponent.formControl.value).toEqual(selected); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -224,13 +224,12 @@ export class MdDatepicker<D> implements OnDestroy { | |
} | ||
|
||
/** Selects the given date and closes the currently open popup or dialog. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: can you update this comment too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohhh... sorry, i missed it |
||
_selectAndClose(date: D): void { | ||
_select(date: D): void { | ||
let oldValue = this._selected; | ||
this._selected = date; | ||
if (!this._dateAdapter.sameDate(oldValue, this._selected)) { | ||
this.selectedChanged.emit(date); | ||
} | ||
this.close(); | ||
} | ||
|
||
/** | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: this should stay the same too. They indent 2 for function blocks and 4 for line breaks