Skip to content

Commit

Permalink
Use portal instead of zIndex for settings menu
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-grace committed Nov 13, 2024
1 parent 57d2eee commit 30b2bc3
Showing 1 changed file with 33 additions and 22 deletions.
55 changes: 33 additions & 22 deletions src/components/SettingsMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { IconButton, Menu, MenuButton, MenuList } from "@chakra-ui/react";
import {
Box,
IconButton,
Menu,
MenuButton,
MenuList,
Portal,
} from "@chakra-ui/react";
import { useRef } from "react";
import { RiSettings2Line } from "react-icons/ri";
import { useIntl } from "react-intl";
Expand All @@ -10,28 +17,32 @@ import LanguageMenuItem from "./LanguageMenuItem";
const SettingsMenu = () => {
const intl = useIntl();
const settingsMenuRef = useRef(null);

const containerRef = useRef(null);
return (
<Menu>
<MenuButton
ref={settingsMenuRef}
as={IconButton}
aria-label={intl.formatMessage({ id: "settings-menu-action" })}
size="lg"
fontSize="2xl"
icon={<RiSettings2Line fill="white" size={24} />}
variant="plain"
isRound
h={12}
w={12}
_focusVisible={{
boxShadow: "outlineDark",
}}
/>
<MenuList zIndex={2}>
<LanguageMenuItem finalFocusRef={settingsMenuRef} />
</MenuList>
</Menu>
<Box ref={containerRef}>
<Menu>
<MenuButton
ref={settingsMenuRef}
as={IconButton}
aria-label={intl.formatMessage({ id: "settings-menu-action" })}
size="lg"
fontSize="2xl"
icon={<RiSettings2Line fill="white" size={24} />}
variant="plain"
isRound
h={12}
w={12}
_focusVisible={{
boxShadow: "outlineDark",
}}
/>
<Portal containerRef={containerRef}>
<MenuList>
<LanguageMenuItem finalFocusRef={settingsMenuRef} />
</MenuList>
</Portal>
</Menu>
</Box>
);
};

Expand Down

0 comments on commit 30b2bc3

Please sign in to comment.