diff --git a/components/date-picker2/__tests__/index-spec.js b/components/date-picker2/__tests__/index-spec.js index 747505d13a..d2d7764938 100644 --- a/components/date-picker2/__tests__/index-spec.js +++ b/components/date-picker2/__tests__/index-spec.js @@ -1223,13 +1223,14 @@ describe('Picker', () => { ); changeInput('2020-11-11'); findInput().simulate('keydown', { keyCode: KEYCODE.SPACE }); - assert(getStrValue(wrapper) === '2020-11-11 00:00:00'); + assert(getStrValue(wrapper) === '2020-11-11 '); + wrapper.unmount(); wrapper = mount( - + ); - changeInput('2021-01-12', 0); + changeInput('2020-11-11', 0); findInput(0).simulate('keydown', { keyCode: KEYCODE.SPACE }); - assert(getStrValue(wrapper).join(',') === '2021-01-12 00:00:00,'); + assert(getStrValue(wrapper).join(',') === '2020-11-11 ,'); }) }); }); diff --git a/components/date-picker2/picker.jsx b/components/date-picker2/picker.jsx index c084b425c8..16522897a4 100644 --- a/components/date-picker2/picker.jsx +++ b/components/date-picker2/picker.jsx @@ -415,9 +415,17 @@ class Picker extends React.Component { break; } case KEYCODE.SPACE: { - const { inputValue } = this.state; + const { inputValue, isRange, inputType } = this.state; this.onClick(); - this.handleChange(inputValue, 'KEYDOWN_SPACE'); + if (isRange) { + const updatedInputValue = [...inputValue]; + updatedInputValue[inputType] = updatedInputValue[inputType] + ' '; + this.setState({ inputValue: updatedInputValue }) + } else { + this.setState({ + inputValue: inputValue + ' ' + }) + } break; } default: @@ -449,21 +457,16 @@ class Picker extends React.Component { // 1. 非 Range 选择 // 2. 非 选择预设时间、面板收起、清空输入 操作 // 3. 不需要切换输入框 - const shouldHidePanel = ( + const shouldHidePanel = !isRange || ['CLICK_PRESET', 'VISIBLE_CHANGE', 'INPUT_CLEAR'].includes(eventType) || - !this.shouldSwitchInput(v) - ) && eventType !== 'KEYDOWN_SPACE'; + !this.shouldSwitchInput(v); if (shouldHidePanel) { this.onVisibleChange(false); if (isValueChanged(v, preValue)) { this.onChange(); } - } else { - if (eventType === 'KEYDOWN_SPACE' && isValueChanged(v, preValue)) { - this.onChange(); - } } } );