Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

react-sidebar

> 编程语言
Open source

A sidebar component for React

1.5K stars0 likes2 views
WebsiteGitHub

About

A sidebar component for React

React Sidebar

React Sidebar is a sidebar component for React 0.14+. It offers the following features:

  • The sidebar can slide over the main content or dock next to it.
  • Touch enabled: swipe to open and close the sidebar like on a native mobile app.
  • Easy to combine with media queries to show the sidebar only when there's enough screen-width (see example).
  • Works on both the left and right side.
  • Tiny size: <2.5kB gzipped
  • MIT license

See a demo here.

Touch specifics

The touch interaction of the React Sidebar mimics the interactions that are supported by Android apps that implement the material design spec:

  • When the sidebar is closed, dragging from the left side of the screen will have the right side of the sidebar follow your finger.
  • When the sidebar is open, sliding your finger over the screen will only affect the sidebar once your finger is over the sidebar.
  • On release, it will call onSetOpen prop if the distance the sidebar was dragged is more than the dragToggleDistance prop.

Note: The sidebar touch functionality doesn't work on IOS because of the "swipe-to-go-back" feature. Therefore the functionality has been disabled on IOS.

Installation

npm install react-sidebar

If you use TypeScript, typings are available on DefinitelyTyped and can be installed with:

npm install @types/react-sidebar

Getting started

By design, React Sidebar does not keep track of whether it is open or not. This has to be done by the parent component. This allows the parent component to make changes to the sidebar and main content based on the open/docked state. An example could be to hide the "show menu" button from the main content when the sidebar is docked.

Because React Sidebar can be toggled by dragging the sidebar into its open/closed position, you will have to pass in an onSetOpen method as a prop to allow the sidebar to control the open state in the parent.

The minimum React component to integrate React Sidebar looks like this:

…

Responsive sidebar

A common use case for a sidebar is to show it automatically when there is enough screen width available. This can be achieved using media queries via window.matchMedia. This again has to be integrated into the parent component so you can use the information to make changes to the sidebar and main content.

…

Supported props

Property name Type Default Description children Anything React can render n/a The main content rootClassName string n/a Add a custom class to the root component sidebarClassName string n/a Add a custom class to the sidebar contentClassName string n/a Add a custom class to the content overlayClassName string n/a Add a custom class to the overlay defaultSidebarWidth number 0 Width in pixles of the sidebar on render. Use this to stop the sidebar from poping in after intial render. (Overrides transitions) sidebar Anything React can render n/a The sidebar content onSetOpen function n/a Callback called when the sidebar wants to change the open prop. Happens after sliding the sidebar and when the overlay is clicked when the sidebar is open. docked boolean false If the sidebar should be always visible open boolean false If the sidebar should be open transitions boolean true If transitions should be enabled touch boolean true If touch gestures should be enabled touchHandleWidth number 20 Width in pixels you can start dragging from the edge when the sidebar is closed. dragToggleDistance number 30 Distance the sidebar has to be dragged before it will open/close after it is released. pullRight boolean false Place the sidebar on the right shadow boolean true Enable/Disable sidebar shadow styles object See below Inline styles. These styles are merged with the defaults and applied to the respective elements. rootId string n/a Add an id to the root component sidebarId string n/a Add an id to the sidebar contentId string n/a Add an id to the content. The driving use case for adding an element id to content was to allow react-scroll to scroll the content area of the site using react-sidebar. overlayId string n/a Add an an id to the overlay

Styles

Styles are passed as an object with 5 keys, root, sidebar, content, overlay and dragHandle, and merged to the following defaults:

…

Acknowledgements

My goal was to make a React Component that implements the material design spec for navigation drawers. My initial attempt was to improve hamburger-basement by arnemart but I quickly figured that I better start from scratch. Still, that project helped me a ton to get started.

GitHub Issues· 36 open

View all on GitHub
  • #192

    Cannot click the other elements

    Updated Mar 25, 2020
  • #198

    Keep Sidebar Content fixed

    Updated Mar 1, 2020
  • #194

    Failed prop type: The prop children is marked as required in Sidebar

    Updated Feb 7, 2020
  • #197

    How to use with children that use flexbox (required by react-native)

    Updated Jan 22, 2020
  • #196

    No label for version 3.0.2

    Updated Nov 27, 2019
  • #195

    Can't render sidebar inside my split pane windows properly

    Updated Oct 29, 2019
  • #193

    Feature Request: Add Custom Event on Overlay

    Updated Oct 2, 2019
  • #191

    bug when press the TAB key

    Updated Aug 30, 2019
  • #190

    Styling Scrollbar

    Updated Jul 14, 2019
  • #189

    React scroll

    Updated Jul 13, 2019

Highlights

  • •The sidebar can slide over the main content or dock next to it.
  • •Touch enabled: swipe to open and close the sidebar like on a native mobile app.
  • •Easy to combine with media queries to show the sidebar only when there's enough screen-width (see example).
  • •Works on both the left and right side.
  • •Tiny size: <2.5kB gzipped
  • •MIT license
  • •When the sidebar is closed, dragging from the left side of the screen will have the right side of the sidebar follow your finger.
  • •When the sidebar is open, sliding your finger over the screen will only affect the sidebar once your finger is over the sidebar.
  • •On release, it will call onSetOpen prop if the distance the sidebar was dragged is more than the dragToggleDistance prop.

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言