File tree Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Expand file tree Collapse file tree 3 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -550,15 +550,15 @@ function InnerRangePicker<DateType>(props: RangePickerProps<DateType>) {
550550 inputDivRef : React . RefObject < HTMLDivElement > ,
551551 resetText : ( ) => void ,
552552 ) => ( {
553+ blurToCancel : ! ! ( picker === 'date' && showTime ) ,
553554 forwardKeyDown,
554555 onBlur,
555556 isClickOutside : ( target : EventTarget | null ) =>
556557 ! ! (
557558 panelDivRef . current &&
558559 ! panelDivRef . current . contains ( target as Node ) &&
559560 inputDivRef . current &&
560- ! inputDivRef . current . contains ( target as Node ) &&
561- onOpenChange
561+ ! inputDivRef . current . contains ( target as Node )
562562 ) ,
563563 onFocus : ( e : React . FocusEvent < HTMLInputElement > ) => {
564564 setActivePickerIndex ( index ) ;
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ export default function usePickerInput({
77 isClickOutside,
88 triggerOpen,
99 forwardKeyDown,
10+ blurToCancel,
1011 onSubmit,
1112 onCancel,
1213 onFocus,
@@ -16,6 +17,7 @@ export default function usePickerInput({
1617 isClickOutside : ( clickElement : EventTarget | null ) => boolean ;
1718 triggerOpen : ( open : boolean ) => void ;
1819 forwardKeyDown : ( e : React . KeyboardEvent < HTMLInputElement > ) => boolean ;
20+ blurToCancel ?: boolean ;
1921 onSubmit : ( ) => void ;
2022 onCancel : ( ) => void ;
2123 onFocus ?: React . FocusEventHandler < HTMLInputElement > ;
@@ -107,7 +109,12 @@ export default function usePickerInput({
107109 addGlobalMouseDownEvent ( ( { target } : MouseEvent ) => {
108110 if ( open && isClickOutside ( target ) ) {
109111 preventBlurRef . current = true ;
110- triggerOpen ( false ) ;
112+
113+ if ( blurToCancel ) {
114+ onCancel ( ) ;
115+ } else {
116+ triggerOpen ( false ) ;
117+ }
111118
112119 // Always set back in case `onBlur` prevented by user
113120 window . setTimeout ( ( ) => {
Original file line number Diff line number Diff line change @@ -761,4 +761,22 @@ describe('Picker.Range', () => {
761761 ) ;
762762 expect ( onOk ) . toHaveBeenCalled ( ) ;
763763 } ) ;
764+
765+ it ( 'datetime will reset by blur' , ( ) => {
766+ const wrapper = mount ( < MomentRangePicker showTime /> ) ;
767+ wrapper . openPicker ( ) ;
768+ wrapper . selectCell ( 11 ) ;
769+
770+ const clickEvent = new Event ( 'mousedown' ) ;
771+ Object . defineProperty ( clickEvent , 'target' , {
772+ get : ( ) => document . body ,
773+ } ) ;
774+ act ( ( ) => {
775+ window . dispatchEvent ( clickEvent ) ;
776+ } ) ;
777+
778+ wrapper . update ( ) ;
779+ expect ( wrapper . isOpen ( ) ) . toBeFalsy ( ) ;
780+ expect ( wrapper . find ( 'input' ) . first ( ) . props ( ) . value ) . toEqual ( '' ) ;
781+ } ) ;
764782} ) ;
You can’t perform that action at this time.
0 commit comments