Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/PickerInput/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ export type RangeValueType<DateType> = [
/** Used for change event, it should always be not undefined */
export type NoUndefinedRangeValueType<DateType> = [start: DateType | null, end: DateType | null];

export interface BaseRangePickerProps<DateType extends object>
extends Omit<SharedPickerProps<DateType>, 'showTime' | 'id'> {
export interface BaseRangePickerProps<DateType extends object> extends Omit<
SharedPickerProps<DateType>,
'showTime' | 'id'
> {
// Structure
id?: SelectorIdType;

Expand Down Expand Up @@ -132,7 +134,8 @@ export interface BaseRangePickerProps<DateType extends object>
}

export interface RangePickerProps<DateType extends object>
extends BaseRangePickerProps<DateType>,
extends
BaseRangePickerProps<DateType>,
Omit<RangeTimeProps<DateType>, 'format' | 'defaultValue' | 'defaultOpenValue'> {}

function getActiveRange(activeIndex: number) {
Expand Down Expand Up @@ -666,7 +669,9 @@ function RangePicker<DateType extends object = any>(
return;
}

lastOperation('input');
if (!needConfirm) {
lastOperation('input');
Comment thread
QDyanbing marked this conversation as resolved.
Outdated
}
Comment thread
QDyanbing marked this conversation as resolved.
Outdated

triggerOpen(true, {
inherit: true,
Expand Down Expand Up @@ -739,7 +744,7 @@ function RangePicker<DateType extends object = any>(
const lastOp = lastOperation();

// Trade as confirm on field leave
if (!mergedOpen && lastOp === 'input') {
if (!mergedOpen && !needConfirm && lastOp === 'input') {
Comment thread
QDyanbing marked this conversation as resolved.
Outdated
triggerOpen(false);
triggerPartConfirm(null, true);
}
Expand Down
49 changes: 49 additions & 0 deletions tests/range.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,55 @@ describe('Picker.Range', () => {
expect(document.querySelector('input').value).toEqual('');
});

it('should not submit unconfirmed values on blur when allowEmpty lets fields switch', () => {
const onChange = jest.fn();
const { container } = render(<DayRangePicker showTime allowEmpty onChange={onChange} />);

openPicker(container, 0);
selectCell(11);

openPicker(container, 1);
openPicker(container, 0);

fireEvent.mouseDown(document.body);
container.querySelectorAll('input')[0].blur();

for (let i = 0; i < 5; i += 1) {
act(() => {
jest.runAllTimers();
});
}

expect(onChange).not.toHaveBeenCalled();
matchValues(container, '', '');
});

it('should not submit typed values on blur before confirm', () => {
const onChange = jest.fn();
const { container } = render(<DayRangePicker showTime allowEmpty onChange={onChange} />);

const startInput = container.querySelectorAll<HTMLInputElement>('input')[0];

startInput.focus();
fireEvent.change(startInput, {
target: {
value: '1990-09-11 00:00:00',
},
});

fireEvent.mouseDown(document.body);
startInput.blur();

for (let i = 0; i < 5; i += 1) {
act(() => {
jest.runAllTimers();
});
}

expect(onChange).not.toHaveBeenCalled();
matchValues(container, '', '');
});

describe('viewDate', () => {
function matchTitle(title: string) {
expect(document.querySelector('.rc-picker-header-view').textContent).toEqual(title);
Expand Down
Loading