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
10 changes: 4 additions & 6 deletions src/Picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,8 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
}
};

const onInternalMouseUp: React.MouseEventHandler<HTMLDivElement> = (...args) => {
if (onMouseUp) {
onMouseUp(...args);
}
const onInternalClick: React.MouseEventHandler<HTMLDivElement> = (...args) => {
onClick?.(...args);

if (inputRef.current) {
inputRef.current.focus();
Expand Down Expand Up @@ -536,11 +534,11 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
})}
style={style}
onMouseDown={onMouseDown}
onMouseUp={onInternalMouseUp}
onMouseUp={onMouseUp}
onMouseEnter={onMouseEnter}
onMouseLeave={onMouseLeave}
onContextMenu={onContextMenu}
onClick={onClick}
onClick={onInternalClick}
>
<div
className={classNames(`${prefixCls}-input`, {
Expand Down
22 changes: 16 additions & 6 deletions tests/picker.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -617,28 +617,38 @@ describe('Picker.Basic', () => {
expect(wrapper.find('input').prop('value')).toEqual('2020-1st');
});

it('click outside should also focus', () => {
const onMouseUp = jest.fn();
const wrapper = mount(<MomentPicker onMouseUp={onMouseUp} />);
it('Picker should open when click inside', () => {
const onClick = jest.fn();
const wrapper = mount(<MomentPicker onClick={onClick} />);
const inputElement = wrapper.find('input').instance() as any as HTMLInputElement;
inputElement.focus = jest.fn();

wrapper.find('.rc-picker').simulate('mouseUp');
wrapper.find('.rc-picker').simulate('click');
expect(inputElement.focus).toHaveBeenCalled();
expect(wrapper.isOpen()).toBeTruthy();

expect(onMouseUp).toHaveBeenCalled();
expect(onClick).toHaveBeenCalled();
});

it('not open when disabled', () => {
const wrapper = mount(<MomentPicker disabled />);
wrapper.find('.rc-picker').simulate('mouseUp');
wrapper.find('.rc-picker').simulate('click');
expect(wrapper.isOpen()).toBeFalsy();

wrapper.setProps({ disabled: false });
expect(wrapper.isOpen()).toBeFalsy();
});

it('not open when mouseup', () => {
const wrapper = mount(<MomentPicker />);
const inputElement = wrapper.find('input').instance() as any as HTMLInputElement;
inputElement.focus = jest.fn();

wrapper.find('.rc-picker').simulate('mouseup');
expect(inputElement.focus).toHaveBeenCalledTimes(0);
expect(wrapper.isOpen()).toBeFalsy();
});

it('defaultOpenValue in timePicker', () => {
resetWarned();
const onChange = jest.fn();
Expand Down