Skip to content

Commit

Permalink
fix: Close appearance menu when selecting a theme
Browse files Browse the repository at this point in the history
fix: Position disclosure correctly when menu has submenu
fix: More reliably close context menus
  • Loading branch information
tommoor committed Mar 26, 2021
1 parent 4166257 commit 889186e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
21 changes: 20 additions & 1 deletion app/components/ContextMenu/MenuItem.js
Expand Up @@ -13,6 +13,7 @@ type Props = {|
href?: string,
target?: "_blank",
as?: string | React.ComponentType<*>,
hide?: () => void,
|};

const MenuItem = ({
Expand All @@ -21,16 +22,34 @@ const MenuItem = ({
selected,
disabled,
as,
hide,
...rest
}: Props) => {
const handleClick = React.useCallback(
(ev) => {
if (onClick) {
onClick(ev);
}
if (hide) {
hide();
}
},
[hide, onClick]
);

return (
<BaseMenuItem
onClick={disabled ? undefined : onClick}
disabled={disabled}
hide={hide}
{...rest}
>
{(props) => (
<MenuAnchor as={onClick ? "button" : as} {...props}>
<MenuAnchor
{...props}
as={onClick ? "button" : as}
onClick={handleClick}
>
{selected !== undefined && (
<>
{selected ? <CheckmarkIcon /> : <Spacer />}
Expand Down
3 changes: 2 additions & 1 deletion app/components/ContextMenu/Template.js
Expand Up @@ -59,7 +59,8 @@ type Props = {|

const Disclosure = styled(ExpandedIcon)`
transform: rotate(270deg);
justify-self: flex-end;
position: absolute;
right: 8px;
`;

const Submenu = React.forwardRef(({ templateItems, title, ...rest }, ref) => {
Expand Down
10 changes: 9 additions & 1 deletion app/menus/AccountMenu.js
Expand Up @@ -19,6 +19,7 @@ import MenuItem, { MenuAnchor } from "components/ContextMenu/MenuItem";
import Separator from "components/ContextMenu/Separator";
import Flex from "components/Flex";
import Modal from "components/Modal";
import usePrevious from "hooks/usePrevious";
import useStores from "hooks/useStores";

type Props = {|
Expand Down Expand Up @@ -74,12 +75,19 @@ function AccountMenu(props: Props) {
placement: "bottom-start",
modal: true,
});
const { auth } = useStores();
const { auth, ui } = useStores();
const previousTheme = usePrevious(ui.theme);
const { t } = useTranslation();
const [keyboardShortcutsOpen, setKeyboardShortcutsOpen] = React.useState(
false
);

React.useEffect(() => {
if (ui.theme !== previousTheme) {
menu.hide();
}
}, [menu, ui.theme, previousTheme]);

return (
<>
<Modal
Expand Down

0 comments on commit 889186e

Please sign in to comment.