@@ -21,7 +21,7 @@ import type { RefTriggerProps } from '../SelectTrigger';
2121import SelectTrigger from '../SelectTrigger' ;
2222import { getSeparatedContent , isValidCount } from '../utils/valueUtil' ;
2323import Polite from './Polite' ;
24- import useOpen from '../hooks/useOpen' ;
24+ import useOpen , { macroTask } from '../hooks/useOpen' ;
2525import { useEvent } from '@rc-component/util' ;
2626import type { SelectInputRef } from '../SelectInput' ;
2727import SelectInput from '../SelectInput' ;
@@ -564,12 +564,11 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
564564 } ;
565565
566566 const onRootBlur = ( ) => {
567- // Delay close should check the activeElement
568- if ( mergedOpen ) {
569- triggerOpen ( false , {
570- cancelFun : ( ) => isInside ( getSelectElements ( ) , document . activeElement as HTMLElement ) ,
571- } ) ;
572- }
567+ macroTask ( ( ) => {
568+ if ( ! isInside ( getSelectElements ( ) , document . activeElement as HTMLElement ) ) {
569+ triggerOpen ( false ) ;
570+ }
571+ } ) ;
573572 } ;
574573
575574 const onInternalBlur : React . FocusEventHandler < HTMLElement > = ( event ) => {
@@ -594,14 +593,16 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
594593 }
595594 } ;
596595
597- const onRootMouseDown : React . MouseEventHandler < HTMLDivElement > = ( event , ...restArgs ) => {
596+ const onInternalMouseDown : React . MouseEventHandler < HTMLDivElement > = ( event , ...restArgs ) => {
598597 const { target } = event ;
599598 const popupElement : HTMLDivElement = triggerRef . current ?. getPopupElement ( ) ;
600599
601600 // We should give focus back to selector if clicked item is not focusable
602601 if ( popupElement ?. contains ( target as HTMLElement ) && triggerOpen ) {
603602 // Tell `open` not to close since it's safe in the popup
604- triggerOpen ( true ) ;
603+ triggerOpen ( true , {
604+ ignoreNext : true ,
605+ } ) ;
605606 }
606607
607608 onMouseDown ?.( event , ...restArgs ) ;
@@ -746,7 +747,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
746747 // Token handling
747748 tokenWithEnter = { tokenWithEnter }
748749 // Open
749- onMouseDown = { onRootMouseDown }
750+ onMouseDown = { onInternalMouseDown }
750751 // Components
751752 components = { mergedComponents }
752753 />
@@ -773,7 +774,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
773774 empty = { emptyOptions }
774775 onPopupVisibleChange = { onTriggerVisibleChange }
775776 onPopupMouseEnter = { onPopupMouseEnter }
776- onPopupMouseDown = { onRootMouseDown }
777+ onPopupMouseDown = { onInternalMouseDown }
777778 onPopupBlur = { onRootBlur }
778779 >
779780 { renderNode }
0 commit comments