Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix side menu

dominik-zeglen667885f4aab3
diff --git a/saleor/static/dashboard-next/AppRoot.tsx b/saleor/static/dashboard-next/AppRoot.tsx
index e7cbea9329..4b65837566 100644
--- a/saleor/static/dashboard-next/AppRoot.tsx
+++ b/saleor/static/dashboard-next/AppRoot.tsx
@@ -101,8 +101,10 @@ const decorate = withStyles(
width: drawerWidth
},
email: {
- cursor: "pointer" as "pointer",
- display: "inline" as "inline"
+ cursor: "pointer",
+ display: "inline-block",
+ height: 48,
+ lineHeight: 48 + "px"
},
emailLabel: {
color: theme.palette.primary.contrastText,
@@ -164,6 +166,9 @@ const decorate = withStyles(
},
userIcon: {
marginRight: theme.spacing.unit
+ },
+ userMenuItem: {
+ textAlign: "right" as "right"
}
}),
{ name: "ResponsiveDrawer" }
@@ -295,10 +300,12 @@ export const AppRoot = decorate(
| "toolBarContent"
| "toolBarMenu"
| "userIcon"
+ | "userMenuItem"
>,
AppRootState
> {
state = { open: false };
+ anchor = React.createRef<HTMLDivElement>();
closeDrawer = () => {
this.setState({ open: false });
@@ -346,7 +353,7 @@ export const AppRoot = decorate(
<div className={classes.spacer} />
<MenuToggle ariaOwns="user-menu">
{({
- anchor,
+ open: menuOpen,
actions: { open: openMenu, close: closeMenu }
}) => {
const handleLogout = () => {
@@ -357,7 +364,8 @@ export const AppRoot = decorate(
<>
<div
className={classes.email}
- onClick={!!anchor ? closeMenu : openMenu}
+ ref={this.anchor}
+ onClick={!menuOpen ? openMenu : undefined}
>
<Hidden smDown>
<Typography
@@ -370,7 +378,7 @@ export const AppRoot = decorate(
<ArrowDropdown
className={[
classes.arrow,
- !!anchor ? classes.rotate : undefined
+ menuOpen ? classes.rotate : undefined
].join(" ")}
/>
</Hidden>
@@ -381,15 +389,17 @@ export const AppRoot = decorate(
</Hidden>
</div>
<Popper
- open={!!anchor}
- anchorEl={anchor}
+ open={menuOpen}
+ anchorEl={this.anchor.current}
transition
disablePortal
+ placement="bottom-end"
>
{({ TransitionProps, placement }) => (
<Grow
{...TransitionProps}
style={{
+ minWidth: "10rem",
transformOrigin:
placement === "bottom"
? "right top"
@@ -399,10 +409,14 @@ export const AppRoot = decorate(
<Paper>
<ClickAwayListener
onClickAway={closeMenu}
+ mouseEvent="onClick"
>
<Menu>
- <MenuItem onClick={handleLogout}>
- {i18n.t("Logout", {
+ <MenuItem
+ className={classes.userMenuItem}
+ onClick={handleLogout}
+ >
+ {i18n.t("Log out", {
context: "button"
})}
</MenuItem>
diff --git a/saleor/static/dashboard-next/components/MenuToggle.tsx b/saleor/static/dashboard-next/components/MenuToggle.tsx
index 086cd896a5..c980b309cb 100644
--- a/saleor/static/dashboard-next/components/MenuToggle.tsx
+++ b/saleor/static/dashboard-next/components/MenuToggle.tsx
@@ -5,41 +5,41 @@ interface MenuToggleProps {
children:
| ((
props: {
- anchor: HTMLElement;
actions: {
open: (event: React.MouseEvent<any>) => void;
close: () => void;
};
+ open: boolean;
}
) => React.ReactElement<any>)
| React.ReactNode;
}
interface MenuToggleState {
- anchor: HTMLElement | null;
+ open: boolean;
}
class MenuToggle extends React.Component<MenuToggleProps, MenuToggleState> {
state = {
- anchor: null
+ open: false
};
handleClick = (event: React.MouseEvent<any>) => {
- this.setState({ anchor: event.currentTarget });
+ this.setState({ open: true });
};
handleClose = () => {
- this.setState({ anchor: null });
+ this.setState({ open: false });
};
render() {
const { children } = this.props;
- const { anchor } = this.state;
+ const { open } = this.state;
if (typeof children === "function") {
return children({
actions: { open: this.handleClick, close: this.handleClose },
- anchor
+ open
});
}
return children;