Skip to content

Commit 3167554

Browse files
committed
Add onYearChange handler
1 parent 4fd85eb commit 3167554

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

docs/datepicker.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ General datepicker component.
4141
|`onFocus`|`func`|`function() {}`||
4242
|`onKeyDown`|`func`|`function() {}`||
4343
|`onMonthChange`|`func`|`function() {}`||
44+
|`onYearChange`|`func`|`function() {}`||
4445
|`onSelect`|`func`|`function() {}`||
4546
|`onWeekSelect`|`func`|||
4647
|`openToDate`|`object`|||
@@ -67,4 +68,4 @@ General datepicker component.
6768
|`value`|`string`|||
6869
|`weekLabel`|`string`|||
6970
|`withPortal`|`bool`|`false`||
70-
|`yearDropdownItemNumber`|`number`|||
71+
|`yearDropdownItemNumber`|`number`|||

src/calendar.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export default class Calendar extends React.Component {
4141
monthsShown: PropTypes.number,
4242
onClickOutside: PropTypes.func.isRequired,
4343
onMonthChange: PropTypes.func,
44+
onYearChange: PropTypes.func,
4445
forceShowMonthNavigation: PropTypes.bool,
4546
onDropdownFocus: PropTypes.func,
4647
onSelect: PropTypes.func.isRequired,
@@ -146,10 +147,16 @@ export default class Calendar extends React.Component {
146147
}
147148
}
148149

150+
handleYearChange = (data) => {
151+
if (this.props.onYearChange) {
152+
this.props.onYearChange(date)
153+
}
154+
}
155+
149156
changeYear = (year) => {
150157
this.setState({
151158
date: this.state.date.clone().set('year', year)
152-
})
159+
}, () => this.handleYearChange(this.state.date))
153160
}
154161

155162
changeMonth = (month) => {

src/datepicker.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default class DatePicker extends React.Component {
5656
onFocus: PropTypes.func,
5757
onKeyDown: PropTypes.func,
5858
onMonthChange: PropTypes.func,
59+
onYearChange: PropTypes.func,
5960
openToDate: PropTypes.object,
6061
peekNextMonth: PropTypes.bool,
6162
placeholderText: PropTypes.string,
@@ -99,6 +100,7 @@ export default class DatePicker extends React.Component {
99100
onSelect () {},
100101
onClickOutside () {},
101102
onMonthChange () {},
103+
onYearChange () {},
102104
utcOffset: moment().utcOffset(),
103105
monthsShown: 1,
104106
withPortal: false
@@ -380,6 +382,7 @@ export default class DatePicker extends React.Component {
380382
monthsShown={this.props.monthsShown}
381383
onDropdownFocus={this.handleDropdownFocus}
382384
onMonthChange={this.props.onMonthChange}
385+
onYearChange={this.props.onYearChange}
383386
dayClassName={this.props.dayClassName}
384387
className={this.props.calendarClassName}
385388
yearDropdownItemNumber={this.props.yearDropdownItemNumber}>

0 commit comments

Comments
 (0)