Skip to content

Commit 78f79b3

Browse files
authored
Merge pull request #6178 from WiXSL/disable-hos
Add container prop to AppBar
2 parents 8ef6045 + 840fb2f commit 78f79b3

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

docs/Theming.md

+15-2
Original file line numberDiff line numberDiff line change
@@ -740,9 +740,22 @@ const App = () => (
740740

741741
## Replacing The AppBar
742742

743-
For more drastic changes of the top component, you will probably want to create an `<AppBar>` from scratch instead of just passing children to react-admin's `<AppBar>`.
743+
By default, React-admin uses [Material-ui's `<AppBar>` component](https://material-ui.com/api/app-bar/) together with a custom container that internally uses a [Slide](https://material-ui.com/api/slide) to hide the `AppBar` on scroll. Here is an example of how to change this container with any component:
744744

745-
By default, React-admin uses [Material-ui's `<AppBar>` component](https://material-ui.com/api/app-bar/) together with [react-headroom](https://github.com/KyleAMathews/react-headroom) to hide the `AppBar` on scroll. Here is an example top bar rebuilt from scratch to remove the "headroom" effect:
745+
```jsx
746+
// in src/MyAppBar.js
747+
import * as React from 'react';
748+
import { Fragment } from 'react';
749+
import { AppBar } from 'react-admin';
750+
751+
const MyAppBar = props => (
752+
<AppBar {...props} container={Fragment} />
753+
);
754+
755+
export default MyAppBar;
756+
```
757+
758+
For more drastic changes of the top component, you will probably want to create an `<AppBar>` from scratch instead of just passing children to react-admin's `<AppBar>`. Here is an example top bar rebuilt from scratch:
746759

747760
```jsx
748761
// in src/MyAppBar.js

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ const AppBar = (props: AppBarProps): JSX.Element => {
103103
open,
104104
title,
105105
userMenu,
106+
container: Container,
106107
...rest
107108
} = props;
108109
const classes = useStyles(props);
@@ -113,7 +114,7 @@ const AppBar = (props: AppBarProps): JSX.Element => {
113114
const translate = useTranslate();
114115

115116
return (
116-
<HideOnScroll>
117+
<Container>
117118
<MuiAppBar className={className} color={color} {...rest}>
118119
<Toolbar
119120
disableGutters
@@ -163,7 +164,7 @@ const AppBar = (props: AppBarProps): JSX.Element => {
163164
: cloneElement(userMenu, { logout })}
164165
</Toolbar>
165166
</MuiAppBar>
166-
</HideOnScroll>
167+
</Container>
167168
);
168169
};
169170

@@ -179,17 +180,20 @@ AppBar.propTypes = {
179180
'secondary',
180181
'transparent',
181182
]),
183+
container: PropTypes.element,
182184
logout: PropTypes.element,
183185
open: PropTypes.bool,
184186
userMenu: PropTypes.oneOfType([PropTypes.element, PropTypes.bool]),
185187
};
186188

187189
AppBar.defaultProps = {
188190
userMenu: <DefaultUserMenu />,
191+
container: HideOnScroll,
189192
};
190193

191194
export interface AppBarProps extends Omit<MuiAppBarProps, 'title' | 'classes'> {
192195
classes?: ClassesOverride<typeof useStyles>;
196+
container?: React.ComponentType<any>;
193197
logout?: React.ReactNode;
194198
open?: boolean;
195199
title?: string | JSX.Element;

0 commit comments

Comments
 (0)