Skip to content

feat(datepicker): add year selection mode - #8565

Merged
andrewseguin merged 7 commits into
angular:masterfrom
mmalerba:dp-years
Jan 12, 2018
Merged

andrewseguin merged 7 commits into
angular:masterfrom
mmalerba:dp-years

Conversation

@mmalerba

@mmalerba mmalerba commented Nov 20, 2017 •

Copy link
Copy Markdown
Contributor

fixes #5845

@mmalerba mmalerba added this to the 5.1 milestone Nov 20, 2017
@mmalerba
mmalerba requested a review from jelbourn November 20, 2017 22:38
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label Nov 20, 2017
Comment thread src/lib/datepicker/calendar.ts Outdated
this._dateAdapter.createDate(curYear - curYear % 24, 0, 1));
let lastYear = this._dateAdapter.getYearName(
this._dateAdapter.createDate(curYear + yearsPerPage - 1 - curYear % 24, 0, 1));
return `${firstYear} \u2013 ${lastYear}`;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Would this need to be internationalized?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It probably should be. I don't think any of our *Intl objects currently have placeholders, so we'd have to make up some convention for that.

Should we switch to using the official Angular i18n stuff? It seems weird that we're just rolling our own.

Comment thread src/lib/datepicker/calendar.ts Outdated
if (this._currentView == 'year') {
return this._dateAdapter.getYearName(this._activeDate);
}
let curYear = this._dateAdapter.getYear(this._activeDate);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

const?

Comment thread src/lib/datepicker/calendar.ts Outdated
let curYear = this._dateAdapter.getYear(this._activeDate);
let firstYear = this._dateAdapter.getYearName(
this._dateAdapter.createDate(curYear - curYear % 24, 0, 1));
let lastYear = this._dateAdapter.getYearName(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about selectedYear, firstYearInView and lastYearInView?

Comment thread src/lib/datepicker/calendar.ts Outdated
}

/** Handles month selection in the multi-year view. */
_yearSelected(year: D): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

_selectYear?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I combined this with _monthSelected and named the new method _goToDateInView

/** Handles user clicks on the previous button. */
_previousClicked(): void {
this._activeDate = this._monthView ?
this._activeDate = this._currentView == 'month' ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Make a _isMonthView() function instead of repeating the comparison?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do we gain anything from the method? seems equally readable to what I'm doing here

if (this._currentView == 'year') {
return this._dateAdapter.getYear(date1) == this._dateAdapter.getYear(date2);
}
return Math.floor(this._dateAdapter.getYear(date1) / yearsPerPage) ==

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add comment like?

// Multi-year view

Comment thread src/lib/datepicker/multi-year-view.html Outdated
<tr><th class="mat-calendar-table-header-divider" colspan="4"></th></tr>
</thead>
<tbody mat-calendar-body
role="grid"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this also needs aria-readonly="true" since role="grid" treats it as editable by default

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, moved both of these to mat-calendar-body since they're the same for all of these views

@Misiu

Misiu commented Dec 5, 2017

Copy link
Copy Markdown

@mmalerba this looks fine.
I'd like to ask for single fix.
When You specify min and max date in calendar view all invalid dates are gray'ed out:
snap 2017-12-05 at 09 35 13

but when You switch to Year view this isn't happening:
snap 2017-12-05 at 09 35 27

Maybe same rule could be applied? Even better would be to hide years that aren't available to pick from (if I have min and max in same Year switching to Year view should be disabled)

@mmalerba

mmalerba commented Dec 7, 2017

Copy link
Copy Markdown
Contributor Author

@Misiu yeah I should do that, I want to make a separate PR first that changes the way some of the logic works behind the scenes for that feature, then I'll add it here

@Misiu

Misiu commented Dec 7, 2017

Copy link
Copy Markdown

@mmalerba I've noticed that with latest changes I can't navigate to year list in demo in first comment (https://mmalerba-demo1.firebaseapp.com/datepicker) is this intended?

@mmalerba

mmalerba commented Dec 7, 2017

Copy link
Copy Markdown
Contributor Author

oh I reused that demo for something else, there's currently no demo for this PR

@Misiu

Misiu commented Dec 7, 2017

Copy link
Copy Markdown

@mmalerba no worries :) I'll wait till it get merged.

@jelbourn jelbourn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, add merge-ready when ready

Comment thread src/lib/datepicker/calendar.spec.ts Outdated
expect(calendarInstance._monthView).toBe(false);
expect(calendarInstance._currentView).toBe('multi-year');

(<HTMLElement>calendarBodyEl.querySelector('.mat-calendar-body-active')).click();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use as HTMLElement (here and elsewhere)

@jelbourn jelbourn added pr: lgtm target: minor This PR is targeted for the next minor release and removed pr: needs review labels Dec 7, 2017
@Toub

Toub commented Jan 8, 2018

Copy link
Copy Markdown

Good job guys!

What is missing in this PR in order to be merged?

@mmalerba mmalerba added the action: merge The PR is ready for merge by the caretaker label Jan 8, 2018
@andrewseguin
andrewseguin merged commit cdbabf7 into angular:master Jan 12, 2018
@mmalerba
mmalerba deleted the dp-years branch July 31, 2018 21:56
@FergusZhou

Copy link
Copy Markdown

@Misiu it seems that what you mentioned (if I have min and max in same Year switching to Year view should be disabled) is not implemented in current version. Do you have any idea about this? Sorry that can't find help with it..

@Misiu

Misiu commented Sep 10, 2018

Copy link
Copy Markdown

@FergusZhou I'm not using Angular currently. Maybe @mmalerba can help You with this.

@angular-automatic-lock-bot

Copy link
Copy Markdown

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 9, 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: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make year selectable in date picker

7 participants