# react-burger-menu
**Repository Path**: trusted-list/react-burger-menu
## Basic Information
- **Project Name**: react-burger-menu
- **Description**: :hamburger: An off-canvas sidebar component with a collection of effects and styles using CSS transitions and SVG path animations
- **Primary Language**: Unknown
- **License**: MIT
- **Default Branch**: main
- **Homepage**: http://negomi.github.io/react-burger-menu/
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2026-09-08
- **Last Updated**: 2026-09-14
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
react-burger-menu [](https://travis-ci.org/negomi/react-burger-menu) [](https://github.com/prettier/prettier)
=================
An off-canvas sidebar React component with a collection of effects and styles using CSS transitions and SVG path animations.
*Using Redux? Check out [redux-burger-menu](https://github.com/negomi/redux-burger-menu) for easy integration of react-burger-menu into your project.*
## Demo & examples
Live demo: [negomi.github.io/react-burger-menu](https://negomi.github.io/react-burger-menu/)
To build the examples locally, first make sure you're using Node <11.0.0. Then run:
```
npm install
npm start
```
Then open [`localhost:8000`](http://localhost:8000) in a browser.
## Tests
The test suite uses [Mocha](https://mochajs.org/), [Chai](https://chaijs.com/) and [Sinon](https://sinonjs.org/), with [jsdom](https://github.com/tmpvar/jsdom).
To run the tests once, run:
```
npm test
```
To run them with a watcher, run:
```
npm run test:watch
```
## Installation
The easiest way to use react-burger-menu is to install it from npm and include it in your own React build process (using [Browserify](https://browserify.org), [Webpack](https://webpack.github.io/), etc).
You can also use the standalone build by including `dist/react-burger-menu.js` in your page. If you use this, make sure you have already included React, and it is available as a global variable.
Version 3.x uses Hooks, so if you're using React 16.8+:
```
npm install react-burger-menu --save
```
If you're using an earlier version of React:
```
npm install react-burger-menu@^2.9.2 --save
```
## Usage
Items for the sidebar should be passed as child elements of the component using JSX.
``` javascript
import { slide as Menu } from 'react-burger-menu'
class Example extends React.Component {
showSettings (event) {
event.preventDefault();
.
.
.
}
render () {
// NOTE: You also need to provide styles, see https://github.com/negomi/react-burger-menu#styling
return (
);
}
}
```
### Animations
The example above imported `slide` which renders a menu that slides in on the page when the burger icon is clicked. To use a different animation you can substitute `slide` with any of the following (check out the [demo](https://negomi.github.io/react-burger-menu/) to see the animations in action):
* `slide`
* `stack`
* `elastic`
* `bubble`
* `push`
* `pushRotate`
* `scaleDown`
* `scaleRotate`
* `fallDown`
* `reveal`
### Properties
Some animations require certain other elements to be on your page:
* **Page wrapper** - an element wrapping the rest of the content on your page (except elements with fixed positioning - see [the wiki](https://github.com/negomi/react-burger-menu/wiki/FAQ#i-have-a-fixed-header-but-its-scrolling-with-the-rest-of-the-page-when-i-open-the-menu) for details), placed after the menu component
``` javascript
.
.
.
```
* **Outer container** - an element containing everything, including the menu component
``` javascript
.
.
.
```
If you are using an animation that requires either/both of these elements, you need to give the element an ID, and pass that ID to the menu component as the `pageWrapId` and `outerContainerId` props respectively.
Check this table to see which animations require these elements:
Animation | `pageWrapId` | `outerContainerId`
--- | :---: | :---:
`slide` | |
`stack` | |
`elastic` | ✓ | ✓
`bubble` | |
`push` | ✓ | ✓
`pushRotate` | ✓ | ✓
`scaleDown` | ✓ | ✓
`scaleRotate` | ✓ | ✓
`fallDown` | ✓ | ✓
`reveal` | ✓ | ✓
#### Position
The menu opens from the left by default. To have it open from the right, use the `right` prop. It's just a boolean so you don't need to specify a value. Then set the position of the button using CSS.
``` javascript
```
#### Width
You can specify the width of the menu with the `width` prop. The default is `300`.
``` javascript
```
#### Open state
You can control whether the sidebar is open or closed with the `isOpen` prop. This is useful if you need to close the menu after a user clicks on an item in it, for example, or if you want to open the menu from some other button in addition to the standard burger icon. The default value is `false`.
``` javascript
// To render the menu open
// To render the menu closed
```
You can see a more detailed example of how to use `isOpen` [here](https://github.com/negomi/react-burger-menu/wiki/FAQ#i-want-to-control-the-open-state-programmatically-but-i-dont-understand-how-to-use-the-isopen-prop).
*Note: If you want to render the menu open initially, you will need to set this property in your parent component's `componentDidMount()` function.*
#### Open menu handler
If you keep the menu state yourself it might be convenient to pass a custom function to be used when the user triggers something that should open the menu.
Called when:
* The user clicks on the burger icon
``` javascript
```
*Note: The menu will NOT open automatically if you pass this prop, so you must handle it yourself.*
#### Close menu handler
If you keep the menu state yourself it might be convenient to pass a custom function to be used when the user triggers something that should close the menu.
Called when:
* The user clicks on the cross icon
* The user clicks on the overlay
* The user hits the escape key
``` javascript
```
*Note: The menu will NOT close automatically if you pass this prop, so you must handle it yourself.*
#### State change
You can detect whether the sidebar is open or closed by passing a callback function to `onStateChange`. The callback will receive an object containing the new state as its first argument.
``` javascript
var isMenuOpen = function(state) {
return state.isOpen;
};
```
#### Close on Escape
By default, the menu will close when the Escape key is pressed. To disable this behavior, you can pass the `disableCloseOnEsc` prop. This is useful in cases where you want the menu to be open all the time, for example if you're implementing a responsive menu that behaves differently depending on the browser width.
``` javascript
```
#### Custom `keydown` handler
For more control over global keypress functionality, you can override the handler that this component sets for `window.addEventListener('keydown', handler)`, and pass a custom function. This could be useful if you are using multiple instances of this component, for example, and want to implement functionality to ensure that a single press of the Escape key closes them all.
``` javascript
const closeAllMenusOnEsc = (e) => {
e = e || window.event;
if (e.key === 'Escape' || e.keyCode === 27) {
this.setState({areMenusOpen: false});
}
};
```
*Note: Using this prop will disable all the default 'close on Escape' functionality, so you will need to handle this (including determining which key was pressed) yourself.*
#### Overlay
You can turn off the default overlay with `noOverlay`.
``` javascript
```
You can disable the overlay click event (i.e. prevent overlay clicks from closing the menu) with `disableOverlayClick`. This can either be a boolean, or a function that returns a boolean.
``` javascript