Skip to content

Commit b1decff

Browse files
mgrdevportmartijnrusschen
authored andcommitted
update preSelection on selected prop change, open calendar on all InputKey events (Hacker0x01#857)
1 parent f549112 commit b1decff

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/datepicker.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ export default class DatePicker extends React.Component {
131131
}
132132
}
133133

134+
componentWillUpdate (nextProps, nextState) {
135+
if (nextProps.selected !== this.props.selected) {
136+
this.setPreSelection(nextProps.selected)
137+
}
138+
}
139+
134140
componentWillUnmount () {
135141
this.clearPreventFocusTimeout()
136142
}
@@ -262,9 +268,7 @@ export default class DatePicker extends React.Component {
262268

263269
onInputKeyDown = (event) => {
264270
if (!this.state.open && !this.props.inline) {
265-
if (/^Arrow/.test(event.key)) {
266-
this.onInputClick()
267-
}
271+
this.onInputClick()
268272
return
269273
}
270274
const copy = moment(this.state.preSelection)

test/datepicker_test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ describe('DatePicker', () => {
362362
var result = data.callback.args[0][0]
363363
expect(result.format(data.testFormat)).to.equal(data.copyM.format(data.testFormat))
364364
})
365+
it('should update the selected date on manual input', () => {
366+
var data = getOnInputKeyDownStuff()
367+
TestUtils.Simulate.change(data.nodeInput, {target: {value: '02/02/2017'}})
368+
TestUtils.Simulate.keyDown(data.nodeInput, {key: 'Enter', keyCode: 13, which: 13})
369+
data.copyM = moment('02/02/2017')
370+
expect(data.callback.args[0][0].format(data.testFormat)).to.equal(data.copyM.format(data.testFormat))
371+
})
365372
it('should not select excludeDates', () => {
366373
var data = getOnInputKeyDownStuff({ excludeDates: [moment().subtract(1, 'days')] })
367374
TestUtils.Simulate.keyDown(data.nodeInput, {key: 'ArrowLeft', keyCode: 37, which: 37})

0 commit comments

Comments
 (0)