Skip to content

Commit

Permalink
feat(datepicker): add 'currentYear' to the day template (#3540)
Browse files Browse the repository at this point in the history
Fixes #2944
  • Loading branch information
maxokorokov committed Jan 10, 2020
1 parent 8016a22 commit bbd8b51
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
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

0 comments on commit bbd8b51

Please sign in to comment.