@@ -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 , { macroTask } from '../hooks/useOpen' ;
24+ import useOpen from '../hooks/useOpen' ;
2525import { useEvent } from '@rc-component/util' ;
2626import type { SelectInputRef } from '../SelectInput' ;
2727import SelectInput from '../SelectInput' ;
@@ -564,11 +564,12 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
564564 } ;
565565
566566 const onRootBlur = ( ) => {
567- macroTask ( ( ) => {
568- if ( ! isInside ( getSelectElements ( ) , document . activeElement as HTMLElement ) ) {
569- triggerOpen ( false ) ;
570- }
571- } ) ;
567+ // Delay close should check the activeElement
568+ if ( mergedOpen ) {
569+ triggerOpen ( false , {
570+ cancelFun : ( ) => isInside ( getSelectElements ( ) , document . activeElement as HTMLElement ) ,
571+ } ) ;
572+ }
572573 } ;
573574
574575 const onInternalBlur : React . FocusEventHandler < HTMLElement > = ( event ) => {
@@ -593,16 +594,14 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
593594 }
594595 } ;
595596
596- const onInternalMouseDown : React . MouseEventHandler < HTMLDivElement > = ( event , ...restArgs ) => {
597+ const onRootMouseDown : React . MouseEventHandler < HTMLDivElement > = ( event , ...restArgs ) => {
597598 const { target } = event ;
598599 const popupElement : HTMLDivElement = triggerRef . current ?. getPopupElement ( ) ;
599600
600601 // We should give focus back to selector if clicked item is not focusable
601602 if ( popupElement ?. contains ( target as HTMLElement ) && triggerOpen ) {
602603 // Tell `open` not to close since it's safe in the popup
603- triggerOpen ( true , {
604- ignoreNext : true ,
605- } ) ;
604+ triggerOpen ( true ) ;
606605 }
607606
608607 onMouseDown ?.( event , ...restArgs ) ;
@@ -747,7 +746,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
747746 // Token handling
748747 tokenWithEnter = { tokenWithEnter }
749748 // Open
750- onMouseDown = { onInternalMouseDown }
749+ onMouseDown = { onRootMouseDown }
751750 // Components
752751 components = { mergedComponents }
753752 />
@@ -774,7 +773,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)
774773 empty = { emptyOptions }
775774 onPopupVisibleChange = { onTriggerVisibleChange }
776775 onPopupMouseEnter = { onPopupMouseEnter }
777- onPopupMouseDown = { onInternalMouseDown }
776+ onPopupMouseDown = { onRootMouseDown }
778777 onPopupBlur = { onRootBlur }
779778 >
780779 { renderNode }
0 commit comments