Skip to content

Commit

Permalink
fix(DatePicker2): Unable to enter space to enter time
Browse files Browse the repository at this point in the history
  • Loading branch information
luolin-ck authored and eternalsky committed Jul 5, 2024
1 parent 9df35fe commit 65faba2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
9 changes: 5 additions & 4 deletions components/date-picker2/__tests__/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<RangePicker showTime />
<RangePicker showTime format="YYYY-MM-DD HH:mm:ss" />
);
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 ,');
})
});
});
Expand Down
21 changes: 12 additions & 9 deletions components/date-picker2/picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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();
}
}
}
);
Expand Down

0 comments on commit 65faba2

Please sign in to comment.