Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 15 additions & 2 deletions src/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ export type RangePickerSharedProps<DateType> = {
onPanelChange?: (values: RangeValue<DateType>, modes: [PanelMode, PanelMode]) => void;
onFocus?: React.FocusEventHandler<HTMLInputElement>;
onBlur?: React.FocusEventHandler<HTMLInputElement>;
onMouseDown?: React.MouseEventHandler<HTMLDivElement>;
onMouseUp?: React.MouseEventHandler<HTMLDivElement>;
onMouseEnter?: React.MouseEventHandler<HTMLDivElement>;
onMouseLeave?: React.MouseEventHandler<HTMLDivElement>;
onClick?: React.MouseEventHandler<HTMLDivElement>;
onOk?: (dates: RangeValue<DateType>) => void;
direction?: 'ltr' | 'rtl';
autoComplete?: string;
Expand Down Expand Up @@ -210,8 +213,11 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
onCalendarChange,
onFocus,
onBlur,
onMouseDown,
onMouseUp,
onMouseEnter,
onMouseLeave,
onClick,
onOk,
onKeyDown,
components,
Expand Down Expand Up @@ -647,9 +653,12 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
});

// ========================== Click Picker ==========================
const onPickerClick = (e: MouseEvent) => {
const onPickerClick = (e: React.MouseEvent<HTMLDivElement>) => {
// When click inside the picker & outside the picker's input elements
// the panel should still be opened
if (onClick) {
onClick(e);
}
if (
!mergedOpen &&
!startInputRef.current.contains(e.target as Node) &&
Expand All @@ -663,8 +672,11 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
}
};

const onPickerMouseDown = (e: MouseEvent) => {
const onPickerMouseDown = (e: React.MouseEvent<HTMLDivElement>) => {
// shouldn't affect input elements if picker is active
if (onMouseDown) {
onMouseDown(e);
}
if (
mergedOpen &&
(startFocused || endFocused) &&
Expand Down Expand Up @@ -1107,6 +1119,7 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onMouseDown={onPickerMouseDown}
onMouseUp={onMouseUp}
{...getDataOrAriaProps(props)}
>
<div
Expand Down
15 changes: 15 additions & 0 deletions tests/range.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1521,4 +1521,19 @@ describe('Picker.Range', () => {
wrapper.keyDown(KeyCode.ENTER);
expect(onCalendarChange).not.toHaveBeenCalled();
});

// https://github.com/ant-design/ant-design/issues/33662
it('range picker should have onClick event', () => {
const handleClick = jest.fn();
const wrapper = mount(<MomentRangePicker onClick={handleClick} />);
wrapper.simulate('click');
expect(handleClick).toHaveBeenCalled();
});

it('range picker should have onMouseDown event', () => {
const handleMouseDown = jest.fn();
const wrapper = mount(<MomentRangePicker onMouseDown={handleMouseDown} />);
wrapper.simulate('mousedown');
expect(handleMouseDown).toHaveBeenCalled();
});
});