Skip to content

Commit b66feea

Browse files
authoredJul 6, 2022
Merge pull request #7930 from marmelab/fix-responsive
[Fix] Stick menu to top when AppBar is collapsed
2 parents 55c19b0 + 8beaec4 commit b66feea

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed
 

‎packages/ra-ui-materialui/src/layout/Layout.tsx

+13-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Menu as DefaultMenu, MenuProps } from './Menu';
1616
import { Error, ErrorProps } from './Error';
1717
import { SkipNavigationButton } from '../button';
1818
import { useSidebarState } from './useSidebarState';
19+
import { useScrollTrigger } from '@mui/material';
1920

2021
export const Layout = (props: LayoutProps) => {
2122
const {
@@ -32,6 +33,7 @@ export const Layout = (props: LayoutProps) => {
3233

3334
const [open] = useSidebarState();
3435
const [errorInfo, setErrorInfo] = useState<ErrorInfo>(null);
36+
let trigger = useScrollTrigger();
3537

3638
const handleError = (error: Error, info: ErrorInfo) => {
3739
setErrorInfo(info);
@@ -40,7 +42,11 @@ export const Layout = (props: LayoutProps) => {
4042
return (
4143
<StyledLayout className={clsx('layout', className)} {...rest}>
4244
<SkipNavigationButton />
43-
<div className={LayoutClasses.appFrame}>
45+
<div
46+
className={clsx(LayoutClasses.appFrame, {
47+
'appbar-is-collapsed': trigger,
48+
})}
49+
>
4450
<AppBar open={open} title={title} />
4551
<main className={LayoutClasses.contentWithSidebar}>
4652
<Sidebar>
@@ -109,13 +115,15 @@ const StyledLayout = styled('div', {
109115
display: 'flex',
110116
flexDirection: 'column',
111117
flexGrow: 1,
112-
[theme.breakpoints.up('xs')]: {
113-
marginTop: theme.spacing(6),
114-
},
118+
marginTop: theme.spacing(6),
119+
transition: 'margin 0.25s ease-in-out',
115120
[theme.breakpoints.down('sm')]: {
116121
marginTop: theme.spacing(7),
117122
},
118123
},
124+
[`& .${LayoutClasses.appFrame}.appbar-is-collapsed`]: {
125+
marginTop: 0,
126+
},
119127
[`& .${LayoutClasses.contentWithSidebar}`]: {
120128
display: 'flex',
121129
flexGrow: 1,
@@ -127,12 +135,10 @@ const StyledLayout = styled('div', {
127135
flexDirection: 'column',
128136
flexGrow: 1,
129137
flexBasis: 0,
138+
padding: 0,
130139
[theme.breakpoints.up('xs')]: {
131140
paddingRight: theme.spacing(2),
132141
paddingLeft: theme.spacing(1),
133142
},
134-
[theme.breakpoints.down('md')]: {
135-
padding: 0,
136-
},
137143
},
138144
}));

0 commit comments

Comments
 (0)
Please sign in to comment.