diff --git a/src/Picker.tsx b/src/Picker.tsx index d309dc8..e551644 100644 --- a/src/Picker.tsx +++ b/src/Picker.tsx @@ -284,10 +284,8 @@ function InnerPicker(props: PickerProps) { } }; - const onInternalMouseUp: React.MouseEventHandler = (...args) => { - if (onMouseUp) { - onMouseUp(...args); - } + const onInternalClick: React.MouseEventHandler = (...args) => { + onClick?.(...args); if (inputRef.current) { inputRef.current.focus(); @@ -536,11 +534,11 @@ function InnerPicker(props: PickerProps) { })} style={style} onMouseDown={onMouseDown} - onMouseUp={onInternalMouseUp} + onMouseUp={onMouseUp} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} onContextMenu={onContextMenu} - onClick={onClick} + onClick={onInternalClick} >
{ expect(wrapper.find('input').prop('value')).toEqual('2020-1st'); }); - it('click outside should also focus', () => { - const onMouseUp = jest.fn(); - const wrapper = mount(); + it('Picker should open when click inside', () => { + const onClick = jest.fn(); + const wrapper = mount(); 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(); - 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(); + 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();