fix mobile flash-of-wrong-nav-menu

In the previous impl, the buttons variant of the menu would appear on first render, and then the breakpoint stuff would adjust and re-render as the compact nav menu. Now I'm using CSS to show/hide instead!
This commit is contained in:
Emi Matchu 2020-11-03 14:57:26 -08:00
parent 2772c3e090
commit 2de840b53e

View file

@ -155,26 +155,31 @@ function UserNavBarSection() {
} }
function NavLinksList({ children }) { function NavLinksList({ children }) {
const navStyle = useBreakpointValue({ base: "menu", md: "buttons" }); return (
<>
if (navStyle === "menu") { <Box display={{ base: "block", md: "none" }}>
return ( <Menu>
<Menu> <MenuButton>
<MenuButton> <NavButton icon={<HamburgerIcon />} />
<NavButton icon={<HamburgerIcon />} /> </MenuButton>
</MenuButton> <MenuList>
<MenuList>{children}</MenuList> {React.Children.map(children, (c) =>
</Menu> React.cloneElement(c, { listVariant: "menu" })
); )}
} else { </MenuList>
return children; </Menu>
} </Box>
<HStack spacing="2" display={{ base: "none", md: "flex" }}>
{React.Children.map(children, (c) =>
React.cloneElement(c, { listVariant: "buttons" })
)}
</HStack>
</>
);
} }
function NavLinkItem(props) { function NavLinkItem({ listVariant, ...props }) {
const navStyle = useBreakpointValue({ base: "menu", md: "buttons" }); if (listVariant === "menu") {
if (navStyle === "menu") {
return <MenuItem {...props} />; return <MenuItem {...props} />;
} else { } else {
return <NavButton {...props} />; return <NavButton {...props} />;