Skip to content

Commit

Permalink
add client check
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhabib committed Nov 25, 2024
1 parent 8aff9b2 commit 9facfd4
Showing 1 changed file with 58 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ export function Menu({
triggerPosition,
}: MenuProps) {
let dividerCount = 0;
const [isClient, setIsClient] = React.useState(false);

React.useEffect(() => {
setIsClient(true);
}, []);

const inlineVars =
triggerPosition &&
Expand All @@ -395,59 +400,61 @@ export function Menu({
});

return (
<BraidPortal>
<MenuRendererContext.Provider value={{ reserveIconSpace }}>
<Box
role="menu"
position="absolute"
style={inlineVars}
zIndex="dropdown"
boxShadow={placement === 'top' ? 'small' : 'medium'}
borderRadius={borderRadius}
background="surface"
marginTop={placement === 'bottom' ? offsetSpace : undefined}
marginBottom={placement === 'top' ? offsetSpace : undefined}
transition="fast"
opacity={!open ? 0 : undefined}
overflow="hidden"
className={[
styles.menuPosition,
!open && styles.menuIsClosed,
width !== 'content' && styles.width[width],
]}
>
isClient && (
<BraidPortal>
<MenuRendererContext.Provider value={{ reserveIconSpace }}>
<Box
paddingY={styles.menuYPadding}
className={styles.menuHeightLimit}
role="menu"
position="absolute"
style={inlineVars}
zIndex="dropdown"
boxShadow={placement === 'top' ? 'small' : 'medium'}
borderRadius={borderRadius}
background="surface"
marginTop={placement === 'bottom' ? offsetSpace : undefined}
marginBottom={placement === 'top' ? offsetSpace : undefined}
transition="fast"
opacity={!open ? 0 : undefined}
overflow="hidden"
className={[
styles.menuPosition,
!open && styles.menuIsClosed,
width !== 'content' && styles.width[width],
]}
>
{Children.map(children, (item, i) => {
if (isDivider(item)) {
dividerCount++;
return item;
}
const menuItemIndex = i - dividerCount;
return (
<MenuRendererItemContext.Provider
key={menuItemIndex}
value={{
isHighlighted: menuItemIndex === highlightIndex,
index: menuItemIndex,
dispatch,
focusTrigger,
}}
>
{item}
</MenuRendererItemContext.Provider>
);
})}
<Box
paddingY={styles.menuYPadding}
className={styles.menuHeightLimit}
>
{Children.map(children, (item, i) => {
if (isDivider(item)) {
dividerCount++;
return item;
}
const menuItemIndex = i - dividerCount;
return (
<MenuRendererItemContext.Provider
key={menuItemIndex}
value={{
isHighlighted: menuItemIndex === highlightIndex,
index: menuItemIndex,
dispatch,
focusTrigger,
}}
>
{item}
</MenuRendererItemContext.Provider>
);
})}
</Box>
<Overlay
boxShadow="borderNeutralLight"
borderRadius={borderRadius}
visible
/>
</Box>
<Overlay
boxShadow="borderNeutralLight"
borderRadius={borderRadius}
visible
/>
</Box>
</MenuRendererContext.Provider>
</BraidPortal>
</MenuRendererContext.Provider>
</BraidPortal>
)
);
}

0 comments on commit 9facfd4

Please sign in to comment.