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

feat(datepicker): add 'currentYear' to the day template #3540

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/datepicker/datepicker-day-template-context.ts
Expand Up @@ -19,6 +19,11 @@ export interface DayTemplateContext {
*/
currentMonth: number;

/**
* The year currently displayed by the datepicker.
*/
currentYear: number;

/**
* Any data you pass using the `[dayTemplateData]` input in the datepicker.
*
Expand Down
8 changes: 8 additions & 0 deletions src/datepicker/datepicker-month-view.spec.ts
Expand Up @@ -187,6 +187,7 @@ class TestComponent {
date: new NgbDate(2016, 7, 4),
context: {
currentMonth: 8,
currentYear: 2016,
$implicit: new NgbDate(2016, 7, 4),
date: new NgbDate(2016, 7, 4),
disabled: false,
Expand All @@ -202,6 +203,7 @@ class TestComponent {
date: new NgbDate(2016, 8, 1),
context: {
currentMonth: 8,
currentYear: 2016,
$implicit: new NgbDate(2016, 8, 1),
date: new NgbDate(2016, 8, 1),
disabled: false,
Expand All @@ -224,6 +226,7 @@ class TestComponent {
date: new NgbDate(2016, 8, 2),
context: {
currentMonth: 8,
currentYear: 2016,
$implicit: new NgbDate(2016, 8, 2),
date: new NgbDate(2016, 8, 2),
disabled: true,
Expand All @@ -239,6 +242,7 @@ class TestComponent {
date: new NgbDate(2016, 8, 3),
context: {
currentMonth: 8,
currentYear: 2016,
$implicit: new NgbDate(2016, 8, 3),
date: new NgbDate(2016, 8, 3),
disabled: false,
Expand All @@ -261,6 +265,7 @@ class TestComponent {
date: new NgbDate(2016, 8, 4),
context: {
currentMonth: 8,
currentYear: 2016,
$implicit: new NgbDate(2016, 8, 4),
date: new NgbDate(2016, 8, 4),
disabled: false,
Expand All @@ -276,6 +281,7 @@ class TestComponent {
date: new NgbDate(2016, 9, 1),
context: {
currentMonth: 8,
currentYear: 2016,
$implicit: new NgbDate(2016, 9, 1),
date: new NgbDate(2016, 9, 1),
disabled: false,
Expand All @@ -298,6 +304,7 @@ class TestComponent {
date: new NgbDate(2016, 9, 2),
context: {
currentMonth: 8,
currentYear: 2016,
$implicit: new NgbDate(2016, 9, 2),
date: new NgbDate(2016, 9, 2),
disabled: false,
Expand All @@ -313,6 +320,7 @@ class TestComponent {
date: new NgbDate(2016, 9, 3),
context: {
currentMonth: 8,
currentYear: 2016,
$implicit: new NgbDate(2016, 9, 3),
date: new NgbDate(2016, 9, 3),
disabled: false,
Expand Down
8 changes: 8 additions & 0 deletions src/datepicker/datepicker-service.spec.ts
Expand Up @@ -1295,6 +1295,14 @@ describe('ngb-datepicker-service', () => {
expect(getDayCtx(0).currentMonth).toBe(10);
});

it(`should generate 'currentYear' for day template`, () => {
service.focus(new NgbDate(2017, 1, 1));
expect(getDayCtx(0).currentYear).toBe(2017);

service.focus(new NgbDate(2018, 1, 1));
expect(getDayCtx(0).currentYear).toBe(2018);
});

it(`should update 'focused' flag and tabindex for day template`, () => {
// off
const date = new NgbDate(2017, 5, 1);
Expand Down
3 changes: 2 additions & 1 deletion src/datepicker/datepicker-tools.ts
Expand Up @@ -193,7 +193,8 @@ export function buildMonth(
$implicit: newDate,
date: newDate,
data: contextUserData,
currentMonth: month.number, disabled,
currentMonth: month.number,
currentYear: month.year, disabled,
focused: false,
selected: false, today
});
Expand Down