Skip to content
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

Merged
merged 6 commits into from
Jan 25, 2018
Merged

fix(datepicker): gray out filtered years in multi-year view #9563

merged 6 commits into from
Jan 25, 2018

Conversation

julianobrasil
Copy link
Contributor

Closes #9516

image

@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Jan 24, 2018
@julianobrasil julianobrasil changed the title fix(datepicker): filter years in multi-year view fix(datepicker): gray out filtered years in multi-year view Jan 24, 2018
testComponent = fixture.componentInstance;
});

it('should disabled years with no enabled days', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*disable

Copy link
Contributor

@mmalerba mmalerba left a 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';
Copy link
Contributor

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();
Copy link
Contributor

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>,
Copy link
Contributor

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));
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

@mmalerba mmalerba added the target: patch This PR is targeted for the next patch release label Jan 24, 2018
@julianobrasil
Copy link
Contributor Author

Comments addressed. "SHIFT+ALT+F" from habit... 😊

Copy link
Contributor

@mmalerba mmalerba left a 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)) {
Copy link
Contributor

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)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed this one

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Jan 24, 2018
fixture = TestBed.createComponent(MultiYearViewWithDateFilter);
fixture.detectChanges();

let multiYearViewDebugElement = fixture.debugElement.query(By.directive(MatMultiYearView));
Copy link
Contributor

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');
Copy link
Contributor

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) {
Copy link
Contributor

@rafaelss95 rafaelss95 Jan 25, 2018

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;
Copy link
Contributor

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;

Copy link
Contributor

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;?

Copy link
Contributor

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

@jelbourn jelbourn merged commit 403ebbd into angular:master Jan 25, 2018
@julianobrasil julianobrasil deleted the fix-datepicker branch January 26, 2018 00:51
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MatDatePicker years not blacked out
6 participants