diff --git a/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.tsx b/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.tsx index 320c6309fc2..f26c47e81f1 100644 --- a/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.tsx +++ b/packages/braid-design-system/src/lib/components/MenuItem/useMenuItem.tsx @@ -173,6 +173,43 @@ export function useMenuItem({ } as const; } +export function MenuItemLeftSlot({ children }: { children?: ReactNode }) { + const menuRendererContext = useContext(MenuRendererContext); + + assert( + menuRendererContext !== null, + `MenuItem must be rendered as an immediate child of a menu. See the documentation for correct usage: https://seek-oss.github.io/braid-design-system/components/MenuItem`, + ); + + const { size } = menuRendererContext; + const iconSpace = useBraidTheme().legacy ? 'small' : iconSlotSpace; + return ( + + +   + + {children ? ( + + {children} + + ) : null} + + ); +} + export interface MenuItemChildrenProps { children: ReactNode; tone: MenuItemTone; @@ -188,9 +225,7 @@ function MenuItemChildren({ formElement = false, }: MenuItemChildrenProps) { const menuRendererContext = useContext(MenuRendererContext); - const legacy = useBraidTheme().legacy; - const iconSpace = legacy ? 'small' : iconSlotSpace; - const badgeSpace = legacy ? 'small' : badgeSlotSpace; + const badgeSpace = useBraidTheme().legacy ? 'small' : badgeSlotSpace; assert( menuRendererContext !== null, @@ -205,28 +240,17 @@ function MenuItemChildren({ const { size, reserveIconSpace } = menuRendererContext; - const leftSlot = - !formElement && (icon || reserveIconSpace) ? ( - - {icon || ( - -   - - )} - - ) : null; - return ( - {leftSlot ? ( - - {leftSlot} - + {!formElement && (icon || reserveIconSpace) ? ( + + + {icon} + + ) : null} - + - + + + - +