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 1, 2024
1 parent df4ecc7 commit 83269e0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
16 changes: 16 additions & 0 deletions components/date-picker2/__tests__/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,22 @@ describe('Picker', () => {
assert(getStrValue() === 'Feb 2, 2020');
assert(wrapper.find(`.next-calendar2-header-text-field`).text() === `Feb2020`);
})

// fix https://github.com/alibaba-fusion/next/issues/4790
it('Unable to enter space to enter time', () => {
wrapper = mount(
<DatePicker showTime />
);
changeInput('2020-11-11');
findInput().simulate('keydown', { keyCode: KEYCODE.SPACE });
assert(getStrValue(wrapper) === '2020-11-11 00:00:00');
wrapper = mount(
<RangePicker showTime />
);
changeInput('2021-01-12', 0);
findInput(0).simulate('keydown', { keyCode: KEYCODE.SPACE });
assert(getStrValue(wrapper).join(',') === '2021-01-12 00:00:00,');
})
});
});

Expand Down
16 changes: 13 additions & 3 deletions components/date-picker2/picker.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ class Picker extends React.Component {
this.handleChange(inputValue, 'KEYDOWN_ENTER');
break;
}
case KEYCODE.SPACE: {
const { inputValue } = this.state;
this.onClick();
this.handleChange(inputValue, 'KEYDOWN_SPACE');
break;
}
default:
return;
}
Expand Down Expand Up @@ -443,17 +449,21 @@ 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);

!this.shouldSwitchInput(v)
) && eventType !== 'KEYDOWN_SPACE';
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 83269e0

Please sign in to comment.