Skip to content

Commit

Permalink
Merge pull request primefaces#15419 from bjuergens/master
Browse files Browse the repository at this point in the history
Calendar - add option to change step size in yearpicker
  • Loading branch information
cetincakiroglu authored May 30, 2024
2 parents 6f810e1 + c254e4e commit febd1e5
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 @@ -605,6 +605,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 @@ -1299,8 +1304,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 @@ -1422,7 +1427,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 @@ -1453,7 +1458,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 @@ -1480,12 +1485,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 febd1e5

Please sign in to comment.