Skip to content

Commit 6485b33

Browse files
authored
fix: blur to trigger change (#838)
* fix: not trigger change if click on the panel * test: add test case
1 parent bf95656 commit 6485b33

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

src/PickerInput/Popup/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export interface PopupProps<DateType extends object = any, PresetValue = DateTyp
4545
needConfirm: boolean;
4646
isInvalid: (date: DateType | DateType[]) => boolean;
4747
onOk: VoidFunction;
48+
49+
onPanelMouseDown?: React.MouseEventHandler<HTMLDivElement>;
4850
}
4951

5052
export default function Popup<DateType extends object = any>(props: PopupProps<DateType>) {
@@ -68,6 +70,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
6870
// Focus
6971
onFocus,
7072
onBlur,
73+
onPanelMouseDown,
7174

7275
// Direction
7376
direction,
@@ -187,6 +190,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
187190
// Container
188191
let renderNode = (
189192
<div
193+
onMouseDown={onPanelMouseDown}
190194
tabIndex={-1}
191195
className={classNames(
192196
containerPrefixCls,
@@ -213,6 +217,7 @@ export default function Popup<DateType extends object = any>(props: PopupProps<D
213217
const offsetUnit = getoffsetUnit(realPlacement, rtl);
214218
renderNode = (
215219
<div
220+
onMouseDown={onPanelMouseDown}
216221
ref={wrapperRef}
217222
className={classNames(`${prefixCls}-range-wrapper`, `${prefixCls}-${picker}-range-wrapper`)}
218223
>

src/PickerInput/RangePicker.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,13 @@ function RangePicker<DateType extends object = any>(
500500
onSharedFocus(event);
501501
};
502502

503-
// >>> Calendar
504-
const onPanelSelect: PickerPanelProps<DateType>['onChange'] = (date: DateType) => {
503+
// >>> MouseDown
504+
const onPanelMouseDown: React.MouseEventHandler<HTMLDivElement> = () => {
505505
lastOperation('panel');
506+
};
506507

508+
// >>> Calendar
509+
const onPanelSelect: PickerPanelProps<DateType>['onChange'] = (date: DateType) => {
507510
const clone: RangeValueType<DateType> = fillIndex(calendarValue, activeIndex, date);
508511

509512
// Only trigger calendar event but not update internal `calendarValue` state
@@ -571,6 +574,7 @@ function RangePicker<DateType extends object = any>(
571574
// Focus
572575
onFocus={onPanelFocus}
573576
onBlur={onSharedBlur}
577+
onPanelMouseDown={onPanelMouseDown}
574578
// Mode
575579
picker={picker}
576580
mode={mergedMode}
@@ -641,7 +645,7 @@ function RangePicker<DateType extends object = any>(
641645

642646
const onSelectorBlur: SelectorProps['onBlur'] = (event, index) => {
643647
triggerOpen(false);
644-
if (!needConfirm) {
648+
if (!needConfirm && lastOperation() === 'input') {
645649
const nextIndex = nextActiveIndex(calendarValue);
646650
flushSubmit(activeIndex, nextIndex === null);
647651
}

tests/new-range.spec.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,9 @@ describe('NewPicker.Range', () => {
676676

677677
// Change start time (manually focus since fireEvent.focus not change activeElement)
678678
openPicker(container);
679-
fireEvent.click(
680-
document.querySelector('.rc-picker-time-panel-column').querySelectorAll('li')[6],
681-
);
679+
const li6 = document.querySelector('.rc-picker-time-panel-column').querySelectorAll('li')[6];
680+
fireEvent.mouseDown(li6);
681+
fireEvent.click(li6);
682682
document.querySelector<HTMLDivElement>('.rc-picker-panel-container').focus();
683683

684684
act(() => {
@@ -696,9 +696,11 @@ describe('NewPicker.Range', () => {
696696
expect(isOpen()).toBeTruthy();
697697

698698
// Select end time
699-
fireEvent.click(
700-
document.querySelector('.rc-picker-time-panel-column').querySelectorAll('li')[11],
701-
);
699+
const li11 = document
700+
.querySelector('.rc-picker-time-panel-column')
701+
.querySelectorAll('li')[11];
702+
fireEvent.mouseDown(li11);
703+
fireEvent.click(li11);
702704

703705
act(() => {
704706
jest.runAllTimers();

0 commit comments

Comments
 (0)