@@ -39,7 +39,13 @@ import {
3939import { combineLatest , map , merge , of , scan , startWith } from 'rxjs' ;
4040import { IMenuManagerService } from '../../../services/menu/menu-manager.service' ;
4141import { useDependency , useObservable } from '../../../utils/di' ;
42- import { keepInteractionInsideSameEmbedBoundary } from '../../../utils/embed-boundary' ;
42+ import {
43+ EMBED_CHILD_UNIT_ID_ATTRIBUTE ,
44+ EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE ,
45+ getEmbedBoundaryOwner ,
46+ getEmbedChildUnitId ,
47+ keepInteractionInsideSameEmbedBoundary ,
48+ } from '../../../utils/embed-boundary' ;
4349import { CustomLabel } from '../../custom-label/CustomLabel' ;
4450
4551const TooltipWrapperContext = createContext ( {
@@ -155,6 +161,10 @@ export function DropdownWrapper(props: Omit<Partial<IDropdownProps>, 'overlay'>
155161 const { dropdownVisible, setDropdownVisible } = useContext ( TooltipWrapperContext ) ;
156162 const triggerRef = useRef < HTMLDivElement > ( null ) ;
157163 const overlayRef = useRef < HTMLDivElement > ( null ) ;
164+ const [ embedBoundary , setEmbedBoundary ] = useState < {
165+ childUnitId ?: string ;
166+ owner ?: string ;
167+ } > ( { } ) ;
158168
159169 useEffect ( ( ) => {
160170 if ( disabled ) {
@@ -178,9 +188,19 @@ export function DropdownWrapper(props: Omit<Partial<IDropdownProps>, 'overlay'>
178188 } , [ dropdownVisible , setDropdownVisible ] ) ;
179189
180190 function handleVisibleChange ( visible : boolean ) {
191+ if ( visible ) {
192+ setEmbedBoundary ( {
193+ childUnitId : getEmbedChildUnitId ( triggerRef . current ) ,
194+ owner : getEmbedBoundaryOwner ( triggerRef . current ) ,
195+ } ) ;
196+ }
181197 setDropdownVisible ( visible ) ;
182198 }
183199
200+ function handleEmbedBoundaryFocusOutside ( event : { currentTarget : EventTarget | null ; target : EventTarget | null ; preventDefault : ( ) => void } ) {
201+ keepInteractionInsideSameEmbedBoundary ( event ) ;
202+ }
203+
184204 return (
185205 < Dropdown
186206 align = { align ?? ( direction === 'rtl' ? 'end' : 'start' ) }
@@ -192,6 +212,12 @@ export function DropdownWrapper(props: Omit<Partial<IDropdownProps>, 'overlay'>
192212 disabled = { disabled }
193213 open = { dropdownVisible }
194214 onOpenChange = { handleVisibleChange }
215+ onFocusOutside = { handleEmbedBoundaryFocusOutside }
216+ onInteractOutside = { handleEmbedBoundaryFocusOutside }
217+ { ...{
218+ [ EMBED_CHILD_UNIT_ID_ATTRIBUTE ] : embedBoundary . childUnitId ,
219+ [ EMBED_INTERACTION_BOUNDARY_OWNER_ATTRIBUTE ] : embedBoundary . owner ,
220+ } }
195221 >
196222 < div ref = { triggerRef } className = "univer-h-full" onClick = { ( e ) => e . stopPropagation ( ) } >
197223 { children }
0 commit comments