File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 1- import type * as React from 'react' ;
2- import { useState , useEffect , useRef } from 'react' ;
31import KeyCode from 'rc-util/lib/KeyCode' ;
2+ import type * as React from 'react' ;
3+ import { useEffect , useRef , useState } from 'react' ;
44import { addGlobalMouseDownEvent , getTargetFromEvent } from '../utils/uiUtil' ;
55
66export default function usePickerInput ( {
@@ -149,10 +149,9 @@ export default function usePickerInput({
149149 useEffect ( ( ) =>
150150 addGlobalMouseDownEvent ( ( e : MouseEvent ) => {
151151 const target = getTargetFromEvent ( e ) ;
152+ const clickedOutside = isClickOutside ( target ) ;
152153
153154 if ( open ) {
154- const clickedOutside = isClickOutside ( target ) ;
155-
156155 if ( ! clickedOutside ) {
157156 preventBlurRef . current = true ;
158157
@@ -163,6 +162,8 @@ export default function usePickerInput({
163162 } else if ( ! focused || clickedOutside ) {
164163 triggerOpen ( false ) ;
165164 }
165+ } else if ( focused && ! clickedOutside ) {
166+ preventBlurRef . current = true ;
166167 }
167168 } ) ,
168169 ) ;
Original file line number Diff line number Diff line change @@ -341,6 +341,21 @@ describe('Picker.Basic', () => {
341341 expect ( mouseDownEvent . defaultPrevented ) . toBeTruthy ( ) ;
342342 } ) ;
343343
344+ it ( 'not fire blur when clickinside and is in focus ' , ( ) => {
345+ const onBlur = jest . fn ( ) ;
346+ const { container } = render (
347+ < MomentPicker onBlur = { onBlur } suffixIcon = { < div className = "suffix-icon" > X</ div > } /> ,
348+ ) ;
349+ openPicker ( container ) ;
350+ keyDown ( KeyCode . ESC ) ;
351+ fireEvent . mouseDown ( container . querySelector ( '.suffix-icon' ) ) ;
352+ fireEvent . blur ( container . querySelector ( 'input' ) ) ;
353+ expect ( onBlur ) . toHaveBeenCalledTimes ( 0 ) ;
354+
355+ fireEvent . blur ( container . querySelector ( 'input' ) ) ;
356+ expect ( onBlur ) . toHaveBeenCalledTimes ( 1 ) ;
357+ } ) ;
358+
344359 describe ( 'full steps' , ( ) => {
345360 [
346361 {
You can’t perform that action at this time.
0 commit comments