-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
fix(datepicker): gray out filtered years in multi-year view #9563
Conversation
testComponent = fixture.componentInstance; | ||
}); | ||
|
||
it('should disabled years with no enabled days', () => { |
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.
*disable
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.
Looks good, just some style nits
import {DateAdapter} from '@angular/material/core'; | ||
import {MatCalendarCell} from './calendar-body'; | ||
import {createMissingDateImplError} from './datepicker-errors'; | ||
import { DateAdapter } from '@angular/material/core'; |
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.
undo
@@ -47,9 +47,9 @@ export class MatMultiYearView<D> implements AfterContentInit { | |||
set activeDate(value: D) { | |||
let oldActiveDate = this._activeDate; | |||
this._activeDate = | |||
this._getValidDateOrNull(this._dateAdapter.deserialize(value)) || this._dateAdapter.today(); | |||
this._getValidDateOrNull(this._dateAdapter.deserialize(value)) || this._dateAdapter.today(); |
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.
undo
@@ -79,8 +79,8 @@ export class MatMultiYearView<D> implements AfterContentInit { | |||
/** The year of the selected date. Null if the selected date is null. */ | |||
_selectedYear: number | null; | |||
|
|||
constructor(@Optional() public _dateAdapter: DateAdapter<D>, | |||
private _changeDetectorRef: ChangeDetectorRef) { | |||
constructor( @Optional() public _dateAdapter: DateAdapter<D>, |
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.
undo
@@ -112,9 +112,9 @@ export class MatMultiYearView<D> implements AfterContentInit { | |||
_yearSelected(year: number) { | |||
let month = this._dateAdapter.getMonth(this.activeDate); | |||
let daysInMonth = | |||
this._dateAdapter.getNumDaysInMonth(this._dateAdapter.createDate(year, month, 1)); |
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.
undo
return true; | ||
} | ||
|
||
let firstOfYear = this._dateAdapter.createDate(year, 0, 1); |
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.
const
Comments addressed. "SHIFT+ALT+F" from habit... 😊 |
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.
LGTM, two more nits though. will add merge ready once they're fixed
@@ -49,7 +49,7 @@ export class MatMultiYearView<D> implements AfterContentInit { | |||
this._activeDate = | |||
this._getValidDateOrNull(this._dateAdapter.deserialize(value)) || this._dateAdapter.today(); | |||
if (Math.floor(this._dateAdapter.getYear(oldActiveDate) / yearsPerPage) != | |||
Math.floor(this._dateAdapter.getYear(this._activeDate) / yearsPerPage)) { | |||
Math.floor(this._dateAdapter.getYear(this._activeDate) / yearsPerPage)) { |
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.
missed this one
@@ -114,7 +114,7 @@ export class MatMultiYearView<D> implements AfterContentInit { | |||
let daysInMonth = | |||
this._dateAdapter.getNumDaysInMonth(this._dateAdapter.createDate(year, month, 1)); | |||
this.selectedChange.emit(this._dateAdapter.createDate(year, month, | |||
Math.min(this._dateAdapter.getDate(this.activeDate), daysInMonth))); | |||
Math.min(this._dateAdapter.getDate(this.activeDate), daysInMonth))); |
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.
missed this one
fixture = TestBed.createComponent(MultiYearViewWithDateFilter); | ||
fixture.detectChanges(); | ||
|
||
let multiYearViewDebugElement = fixture.debugElement.query(By.directive(MatMultiYearView)); |
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.
const
}); | ||
|
||
it('should disablex years with no enabled days', () => { | ||
let cells = multiYearViewNativeElement.querySelectorAll('.mat-calendar-body-cell'); |
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.
const
class MultiYearViewWithDateFilter { | ||
activeDate = new Date(2017, JAN, 1); | ||
dateFilter(date: Date) { | ||
if (date.getFullYear() == 2017) { |
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.
What about return date.getFullYear() !== 2017;
?
@@ -31,7 +31,7 @@ export class DatepickerDemo { | |||
lastDateInput: Date | null; | |||
lastDateChange: Date | null; | |||
|
|||
dateFilter = (date: Date) => date.getMonth() % 2 == 1 && date.getDate() % 2 == 0; | |||
dateFilter = (date: Date) => date.getFullYear() % 2 == 0 && date.getMonth() % 2 == 1 && date.getDate() % 2 == 0; |
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.
Could be simplified to !date.getFullYear() && date.getMonth() % 2 == 1 && !date.getDate() % 2;
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.
Assume you meant: !date.getFullYear() % 2 && date.getMonth() % 2 && !date.getDate() % 2;
?
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.
Ups, yes. Bad copy/paste :D
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Closes #9516