Skip to content

Commit

Permalink
Calendar - add option to change step size in yearpicker
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name authored and Björn Jürgens committed May 1, 2024
1 parent 950d6d3 commit c254e4e
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/app/components/calendar/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,11 @@ export class Calendar implements OnInit, OnDestroy, ControlValueAccessor {
* @group Props
*/
@Input({ transform: booleanAttribute }) timeOnly: boolean | undefined;
/**
* Years to change per step in yearpicker.
* @group Props
*/
@Input({ transform: numberAttribute }) stepYearPicker: number = 20;
/**
* Hours to change per step.
* @group Props
Expand Down Expand Up @@ -1284,8 +1289,8 @@ export class Calendar implements OnInit, OnDestroy, ControlValueAccessor {

yearPickerValues() {
let yearPickerValues = [];
let base = <number>this.currentYear - (<number>this.currentYear % 10);
for (let i = 0; i < 10; i++) {
let base = <number>this.currentYear - (<number>this.currentYear % this.stepYearPicker);
for (let i = 0; i < this.stepYearPicker; i++) {
yearPickerValues.push(base + i);
}

Expand Down Expand Up @@ -1407,7 +1412,7 @@ export class Calendar implements OnInit, OnDestroy, ControlValueAccessor {
this.updateFocus();
}, 1);
} else if (this.currentView === 'year') {
this.decrementDecade();
this.decrementYearPickerStep();
setTimeout(() => {
this.updateFocus();
}, 1);
Expand Down Expand Up @@ -1438,7 +1443,7 @@ export class Calendar implements OnInit, OnDestroy, ControlValueAccessor {
this.updateFocus();
}, 1);
} else if (this.currentView === 'year') {
this.incrementDecade();
this.incrementYearPickerStep();
setTimeout(() => {
this.updateFocus();
}, 1);
Expand All @@ -1465,12 +1470,12 @@ export class Calendar implements OnInit, OnDestroy, ControlValueAccessor {
}
}

decrementDecade() {
this.currentYear = this.currentYear - 10;
decrementYearPickerStep() {
this.currentYear = this.currentYear - this.stepYearPicker;
}

incrementDecade() {
this.currentYear = this.currentYear + 10;
incrementYearPickerStep() {
this.currentYear = this.currentYear + this.stepYearPicker;
}

incrementYear() {
Expand Down

0 comments on commit c254e4e

Please sign in to comment.