Skip to content

Commit cb84cbe

Browse files
author
Tobias Schweizer
committed
refactor (MatDatepicker): make select a public method
1 parent 9ecea96 commit cb84cbe

File tree

5 files changed

+6
-28
lines changed

5 files changed

+6
-28
lines changed

src/lib/datepicker/calendar.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {Direction, Directionality} from '@angular/cdk/bidi';
2-
import {ENTER, RIGHT_ARROW,} from '@angular/cdk/keycodes';
2+
import {ENTER, RIGHT_ARROW} from '@angular/cdk/keycodes';
33
import {
44
dispatchFakeEvent,
55
dispatchKeyboardEvent,

src/lib/datepicker/calendar.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,6 @@ export class MatCalendar<D> implements AfterContentInit, AfterViewChecked, OnDes
340340
(this.currentView == 'year' ? this.yearView : this.multiYearView);
341341

342342
view.ngAfterContentInit();
343-
344-
// to be removed once test works
345-
console.log(view._dateAdapter.today());
346343
}
347344

348345
/** Handles date selection in the month view. */

src/lib/datepicker/datepicker-content.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
[headerComponent]="datepicker.calendarHeaderComponent"
1010
[selected]="datepicker._selected"
1111
[@fadeInCalendar]="'enter'"
12-
(selectedChange)="datepicker._select($event)"
12+
(selectedChange)="datepicker.select($event)"
1313
(yearSelected)="datepicker._selectYear($event)"
1414
(monthSelected)="datepicker._selectMonth($event)"
1515
(_userSelection)="datepicker.close()">

src/lib/datepicker/datepicker.spec.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -622,20 +622,6 @@ describe('MatDatepicker', () => {
622622
expect(testComponent.selected).toBeNull();
623623
expect(testComponent.datepickerInput.value).toBeNull();
624624

625-
let selected = new Date(2017, JAN, 1);
626-
testComponent.datepicker._select(selected);
627-
fixture.detectChanges();
628-
flush();
629-
fixture.detectChanges();
630-
631-
expect(testComponent.selected).toEqual(selected);
632-
expect(testComponent.datepickerInput.value).toEqual(selected);
633-
}));
634-
635-
it('should update model when date is selected using the public method', fakeAsync(() => {
636-
expect(testComponent.selected).toBeNull();
637-
expect(testComponent.datepickerInput.value).toBeNull();
638-
639625
let selected = new Date(2017, JAN, 1);
640626
testComponent.datepicker.select(selected);
641627
fixture.detectChanges();
@@ -663,7 +649,7 @@ describe('MatDatepicker', () => {
663649

664650
expect(inputEl.classList).toContain('ng-pristine');
665651

666-
testComponent.datepicker._select(new Date(2017, JAN, 1));
652+
testComponent.datepicker.select(new Date(2017, JAN, 1));
667653
fixture.detectChanges();
668654
flush();
669655
fixture.detectChanges();
@@ -737,7 +723,7 @@ describe('MatDatepicker', () => {
737723

738724
expect(inputEl.classList).toContain('ng-untouched');
739725

740-
testComponent.datepicker._select(new Date(2017, JAN, 1));
726+
testComponent.datepicker.select(new Date(2017, JAN, 1));
741727
fixture.detectChanges();
742728
flush();
743729
fixture.detectChanges();
@@ -779,7 +765,7 @@ describe('MatDatepicker', () => {
779765
expect(testComponent.datepickerInput.value).toBeNull();
780766

781767
let selected = new Date(2017, JAN, 1);
782-
testComponent.datepicker._select(selected);
768+
testComponent.datepicker.select(selected);
783769
fixture.detectChanges();
784770

785771
expect(testComponent.formControl.value).toEqual(selected);

src/lib/datepicker/datepicker.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,8 @@ export class MatDatepicker<D> implements OnDestroy, CanColor {
289289
}
290290
}
291291

292-
/** Public method to select a date in the Datepicker */
293-
select(date: D): void {
294-
this._select(date);
295-
}
296-
297292
/** Selects the given date */
298-
_select(date: D): void {
293+
select(date: D): void {
299294
let oldValue = this._selected;
300295
this._selected = date;
301296
if (!this._dateAdapter.sameDate(oldValue, this._selected)) {

0 commit comments

Comments
 (0)