Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Custom Menu doesn't always receive onMenuClick prop #5435

Merged
merged 1 commit into from
Oct 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 59 additions & 55 deletions packages/ra-ui-materialui/src/layout/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,60 +11,6 @@ import { ClassesOverride } from '../types';
export const DRAWER_WIDTH = 240;
export const CLOSED_DRAWER_WIDTH = 55;

const useStyles = makeStyles(
theme => ({
root: {},
docked: {},
paper: {},
paperAnchorLeft: {},
paperAnchorRight: {},
paperAnchorTop: {},
paperAnchorBottom: {},
paperAnchorDockedLeft: {},
paperAnchorDockedTop: {},
paperAnchorDockedRight: {},
paperAnchorDockedBottom: {},
modal: {},
drawerPaper: {
position: 'relative',
height: '100%',
overflowX: 'hidden',
width: (props: { open?: boolean }) =>
props.open
? lodashGet(theme, 'sidebar.width', DRAWER_WIDTH)
: lodashGet(
theme,
'sidebar.closedWidth',
CLOSED_DRAWER_WIDTH
),
transition: theme.transitions.create('width', {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
backgroundColor: 'transparent',
borderRight: 'none',
[theme.breakpoints.only('xs')]: {
marginTop: 0,
height: '100vh',
position: 'inherit',
backgroundColor: theme.palette.background.default,
},
[theme.breakpoints.up('md')]: {
border: 'none',
},
zIndex: 'inherit',
},
}),
{ name: 'RaSidebar' }
);

export interface SidebarProps extends DrawerProps {
children: ReactElement;
closedSize?: number;
classes: ClassesOverride<typeof useStyles>;
size?: number;
}

const Sidebar = (props: SidebarProps) => {
const {
children,
Expand Down Expand Up @@ -127,7 +73,9 @@ const Sidebar = (props: SidebarProps) => {
classes={classes}
{...rest}
>
{children}
{cloneElement(Children.only(children), {
onMenuClick: defaultOnMenuClick,
})}
</Drawer>
);
};
Expand All @@ -136,4 +84,60 @@ Sidebar.propTypes = {
children: PropTypes.node.isRequired,
};

const defaultOnMenuClick = () => null;

const useStyles = makeStyles(
theme => ({
root: {},
docked: {},
paper: {},
paperAnchorLeft: {},
paperAnchorRight: {},
paperAnchorTop: {},
paperAnchorBottom: {},
paperAnchorDockedLeft: {},
paperAnchorDockedTop: {},
paperAnchorDockedRight: {},
paperAnchorDockedBottom: {},
modal: {},
drawerPaper: {
position: 'relative',
height: '100%',
overflowX: 'hidden',
width: (props: { open?: boolean }) =>
props.open
? lodashGet(theme, 'sidebar.width', DRAWER_WIDTH)
: lodashGet(
theme,
'sidebar.closedWidth',
CLOSED_DRAWER_WIDTH
),
transition: theme.transitions.create('width', {
easing: theme.transitions.easing.sharp,
duration: theme.transitions.duration.leavingScreen,
}),
backgroundColor: 'transparent',
borderRight: 'none',
[theme.breakpoints.only('xs')]: {
marginTop: 0,
height: '100vh',
position: 'inherit',
backgroundColor: theme.palette.background.default,
},
[theme.breakpoints.up('md')]: {
border: 'none',
},
zIndex: 'inherit',
},
}),
{ name: 'RaSidebar' }
);

export interface SidebarProps extends DrawerProps {
children: ReactElement;
closedSize?: number;
classes: ClassesOverride<typeof useStyles>;
size?: number;
}

export default Sidebar;