File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -272,6 +272,18 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
272272 }
273273 } ;
274274
275+ const onInternalMouseUp : React . MouseEventHandler < HTMLDivElement > = (
276+ ...args
277+ ) => {
278+ if ( onMouseUp ) {
279+ onMouseUp ( ...args ) ;
280+ }
281+
282+ if ( inputRef . current ) {
283+ inputRef . current . focus ( ) ;
284+ }
285+ } ;
286+
275287 // ============================= Input =============================
276288 const [ inputProps , { focused, typing } ] = usePickerInput ( {
277289 blurToCancel : needConfirmButton ,
@@ -428,7 +440,7 @@ function InnerPicker<DateType>(props: PickerProps<DateType>) {
428440 } ) }
429441 style = { style }
430442 onMouseDown = { onMouseDown }
431- onMouseUp = { onMouseUp }
443+ onMouseUp = { onInternalMouseUp }
432444 onMouseEnter = { onMouseEnter }
433445 onMouseLeave = { onMouseLeave }
434446 onContextMenu = { onContextMenu }
Original file line number Diff line number Diff line change @@ -546,4 +546,15 @@ describe('Picker.Basic', () => {
546546
547547 expect ( wrapper . find ( 'input' ) . prop ( 'value' ) ) . toEqual ( '2020-1st' ) ;
548548 } ) ;
549+
550+ it ( 'click outside should also focus' , ( ) => {
551+ const wrapper = mount ( < MomentPicker /> ) ;
552+ const inputElement = ( wrapper
553+ . find ( 'input' )
554+ . instance ( ) as any ) as HTMLInputElement ;
555+ inputElement . focus = jest . fn ( ) ;
556+
557+ wrapper . find ( '.rc-picker' ) . simulate ( 'mouseUp' ) ;
558+ expect ( inputElement . focus ) . toHaveBeenCalled ( ) ;
559+ } ) ;
549560} ) ;
You can’t perform that action at this time.
0 commit comments