@@ -15,6 +15,8 @@ import type {ForwardRefComponent as PolymorphicForwardRefComponent} from '../uti
1515import { Tooltip } from '../TooltipV2/Tooltip'
1616import styles from './ActionMenu.module.css'
1717import { useResponsiveValue , type ResponsiveValue } from '../hooks/useResponsiveValue'
18+ import { isSlot } from '../utils/is-slot'
19+ import type { FCWithSlotMarker , WithSlotMarker } from '../utils/types/Slots'
1820
1921export type MenuCloseHandler = (
2022 gesture : 'anchor-click' | 'click-outside' | 'escape' | 'tab' | 'item-select' | 'arrow-left' | 'close' ,
@@ -71,7 +73,7 @@ const mergeAnchorHandlers = (anchorProps: React.HTMLAttributes<HTMLElement>, but
7173 return mergedAnchorProps
7274}
7375
74- const Menu : React . FC < React . PropsWithChildren < ActionMenuProps > > = ( {
76+ const Menu : FCWithSlotMarker < React . PropsWithChildren < ActionMenuProps > > = ( {
7577 anchorRef : externalAnchorRef ,
7678 open,
7779 onOpenChange,
@@ -112,7 +114,7 @@ const Menu: React.FC<React.PropsWithChildren<ActionMenuProps>> = ({
112114 // 🚨 Accounting for Tooltip wrapping ActionMenu.Button or being a direct child of ActionMenu.Anchor.
113115 const contents = React . Children . map ( children , child => {
114116 // Is ActionMenu.Button wrapped with Tooltip? If this is the case, our anchor is the tooltip's trigger (ActionMenu.Button's grandchild)
115- if ( child . type === Tooltip ) {
117+ if ( child . type === Tooltip || isSlot ( child , Tooltip ) ) {
116118 // tooltip trigger
117119 const anchorChildren = child . props . children
118120 if ( anchorChildren . type === MenuButton ) {
@@ -129,7 +131,8 @@ const Menu: React.FC<React.PropsWithChildren<ActionMenuProps>> = ({
129131 return null
130132 } else if ( child . type === Anchor ) {
131133 const anchorChildren = child . props . children
132- const isWrappedWithTooltip = anchorChildren !== undefined ? anchorChildren . type === Tooltip : false
134+ const isWrappedWithTooltip =
135+ anchorChildren !== undefined ? anchorChildren . type === Tooltip || isSlot ( anchorChildren , Tooltip ) : false
133136 if ( isWrappedWithTooltip ) {
134137 if ( anchorChildren . props . children !== null ) {
135138 renderAnchor = anchorProps => {
@@ -175,7 +178,15 @@ const Menu: React.FC<React.PropsWithChildren<ActionMenuProps>> = ({
175178}
176179
177180export type ActionMenuAnchorProps = { children : React . ReactElement ; id ?: string } & React . HTMLAttributes < HTMLElement >
178- const Anchor = React . forwardRef < HTMLElement , ActionMenuAnchorProps > ( ( { children : child , ...anchorProps } , anchorRef ) => {
181+ const Anchor : WithSlotMarker <
182+ React . ForwardRefExoticComponent <
183+ {
184+ children : React . ReactElement
185+ id ?: string
186+ } & React . HTMLAttributes < HTMLElement > &
187+ React . RefAttributes < HTMLElement >
188+ >
189+ > = React . forwardRef < HTMLElement , ActionMenuAnchorProps > ( ( { children : child , ...anchorProps } , anchorRef ) => {
179190 const { onOpen, isSubmenu} = React . useContext ( MenuContext )
180191
181192 const openSubmenuOnRightArrow : React . KeyboardEventHandler < HTMLElement > = useCallback (
@@ -247,7 +258,7 @@ type MenuOverlayProps = Partial<OverlayProps> &
247258 children : React . ReactNode
248259 onPositionChange ?: ( { position} : { position : AnchorPosition } ) => void
249260 }
250- const Overlay : React . FC < React . PropsWithChildren < MenuOverlayProps > > = ( {
261+ const Overlay : FCWithSlotMarker < React . PropsWithChildren < MenuOverlayProps > > = ( {
251262 children,
252263 align = 'start' ,
253264 side,
@@ -323,4 +334,10 @@ const Overlay: React.FC<React.PropsWithChildren<MenuOverlayProps>> = ({
323334}
324335
325336Menu . displayName = 'ActionMenu'
337+
338+ Menu . __SLOT__ = Symbol ( 'ActionMenu' )
339+ MenuButton . __SLOT__ = Symbol ( 'ActionMenu.Button' )
340+ Anchor . __SLOT__ = Symbol ( 'ActionMenu.Anchor' )
341+ Overlay . __SLOT__ = Symbol ( 'ActionMenu.Overlay' )
342+
326343export const ActionMenu = Object . assign ( Menu , { Button : MenuButton , Anchor, Overlay, Divider} )
0 commit comments