Skip to content

Commit 7131aa8

Browse files
fzaninottoAijeyomah
authored andcommitted
Fix collapsed menu in B&W theme
1 parent 223c729 commit 7131aa8

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

examples/demo/src/layout/Menu.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import * as React from 'react';
22
import { useState } from 'react';
33
import { Box } from '@mui/material';
44
import LabelIcon from '@mui/icons-material/Label';
5-
65
import {
76
useTranslate,
87
DashboardMenuItem,
98
MenuItemLink,
109
MenuProps,
1110
useSidebarState,
1211
} from 'react-admin';
12+
import clsx from 'clsx';
1313

1414
import visitors from '../visitors';
1515
import orders from '../orders';
@@ -46,6 +46,10 @@ const Menu = ({ dense = false }: MenuProps) => {
4646
duration: theme.transitions.duration.leavingScreen,
4747
}),
4848
}}
49+
className={clsx({
50+
'RaMenu-open': open,
51+
'RaMenu-closed': !open,
52+
})}
4953
>
5054
<DashboardMenuItem />
5155
<SubMenu

packages/ra-ui-materialui/src/layout/Sidebar.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react';
22
import { styled } from '@mui/material/styles';
3+
import clsx from 'clsx';
34
import { ReactElement } from 'react';
45
import {
56
Drawer,
@@ -40,9 +41,12 @@ export const Sidebar = (props: SidebarProps) => {
4041
open={open}
4142
onClose={toggleSidebar}
4243
classes={SidebarClasses}
43-
className={
44-
trigger && !appBarAlwaysOn ? SidebarClasses.appBarCollapsed : ''
45-
}
44+
className={clsx(
45+
trigger && !appBarAlwaysOn
46+
? SidebarClasses.appBarCollapsed
47+
: '',
48+
open ? OPEN_CLASS : CLOSED_CLASS
49+
)}
4650
{...rest}
4751
>
4852
<div className={SidebarClasses.fixed}>{children}</div>
@@ -75,6 +79,9 @@ export const SidebarClasses = {
7579
appBarCollapsed: `${PREFIX}-appBarCollapsed`,
7680
};
7781

82+
const OPEN_CLASS = `${PREFIX}-open`;
83+
const CLOSED_CLASS = `${PREFIX}-closed`;
84+
7885
const StyledDrawer = styled(Drawer, {
7986
name: PREFIX,
8087
slot: 'Root',

packages/ra-ui-materialui/src/theme/bwTheme.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ const createBWTheme = (mode: 'light' | 'dark'): RaThemeOptions => {
343343
root: {
344344
margin: `0 ${SPACING}px`,
345345
paddingRight: 0,
346+
paddingLeft: SPACING,
346347
borderRadius: 5,
347348
color: isDarkMode ? grey['200'] : common['black'],
348349
'&.RaMenuItemLink-active': {
@@ -351,13 +352,16 @@ const createBWTheme = (mode: 'light' | 'dark'): RaThemeOptions => {
351352
'& .RaMenuItemLink-icon': {
352353
minWidth: 30,
353354
},
355+
'.RaMenu-closed &': {
356+
margin: `0 0 0 ${SPACING}px`,
357+
},
354358
},
355359
},
356360
},
357361
},
358362
sidebar: {
359363
width: 195,
360-
closedWidth: 50,
364+
closedWidth: 45,
361365
},
362366
};
363367
};

0 commit comments

Comments
 (0)