Drawer
React Drawer
Responsive React navigation Drawer built with the latest Bootstrap 5. Examples like sliding side drawer in a container, multilevel, material, right drawer & more.
If you need a more advanced Drawer and more options, see our main SideNav documentation.
Note: Read the API tab to find all available options and advanced customization
Basic example
In the basic version, the side navigation will appear over your website's content after clicking on a toggler.
Note: Use isOpen
property to toggle navigation. Use the getOpenState
property function to synchronize inner and outter open state.
import React, { useState } from 'react';
import {
MDBSideNav,
MDBSideNavMenu,
MDBSideNavItem,
MDBSideNavLink,
MDBSideNavCollapse,
MDBBtn,
MDBIcon
} from 'mdb-react-ui-kit';
export default function App() {
const [basicOpen, setBasicOpen] = useState(true);
const [basicCollapse1, setBasicCollapse1] = useState(true);
const [basicCollapse2, setBasicCollapse2] = useState(false);
return (
<>
<MDBSideNav isOpen={basicOpen} absolute getOpenState={(e: any) => setBasicOpen(e)}>
<MDBSideNavMenu>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon far icon='smile' className='fa-fw me-3' />
Link 1
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink icon='angle-down' shouldBeExpanded={basicCollapse1} onClick={() => setBasicCollapse1(!basicCollapse1)}>
<MDBIcon fas icon='grin' className='fa-fw me-3' />
Category 1
</MDBSideNavLink>
<MDBSideNavCollapse show={basicCollapse1}>
<MDBSideNavLink>Link 2</MDBSideNavLink>
<MDBSideNavLink>Link 3</MDBSideNavLink>
</MDBSideNavCollapse>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink icon='angle-down' shouldBeExpanded={basicCollapse2} onClick={() => setBasicCollapse2(!basicCollapse2)}>
<MDBIcon fas icon='grin' className='fa-fw me-3' />
Category 2
</MDBSideNavLink>
<MDBSideNavCollapse show={basicCollapse2}>
<MDBSideNavLink>Link 4</MDBSideNavLink>
<MDBSideNavLink>Link 5</MDBSideNavLink>
</MDBSideNavCollapse>
</MDBSideNavItem>
</MDBSideNavMenu>
</MDBSideNav>
<div style={{ padding: '20px' }} className='text-center'>
<MDBBtn onClick={() => setBasicOpen(!basicOpen)}>
<MDBIcon fas icon='bars' />
</MDBBtn>
</div>
</>
);
}
Inner scroll
Passing a selector of an inner element to the
scrollContainer
option will initialize MDB scrollbar only on this container (by
default it's initialized on the sidenav's main element).
Use <MDBScrollbar>
instead of <MDBSideNavMenu>
component to create a scrollable menu.
Note: For customization purposes - you have to calculate the height on your own.
import React, { useState } from 'react';
import {
MDBSideNav,
MDBScrollbar,
MDBSideNavItem,
MDBSideNavLink,
MDBBtn,
MDBIcon
} from 'mdb-react-ui-kit';
export default function App() {
const [innerOpen, setInnerOpen] = useState(true);
return (
<>
<MDBSideNav isOpen={innerOpen} absolute getOpenState={(e: any) => setInnerOpen(e)}>
<div className='text-center'>
<h3 className='py-4'>Examples</h3>
<hr className='m-0' />
</div>
<MDBScrollbar sidenav tag='ul' suppressScrollX style={{ height: '260px' }}>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon far icon='smile' className='fa-fw me-3' />
<span className='sidenav-non-slim'>Link 1</span>
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon far icon='smile' className='fa-fw me-3' />
<span className='sidenav-non-slim'>Link 2</span>
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon far icon='smile' className='fa-fw me-3' />
<span className='sidenav-non-slim'>Link 3</span>
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon far icon='smile' className='fa-fw me-3' />
<span className='sidenav-non-slim'>Link 4</span>
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon far icon='smile' className='fa-fw me-3' />
<span className='sidenav-non-slim'>Link 5</span>
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon far icon='smile' className='fa-fw me-3' />
<span className='sidenav-non-slim'>Link 6</span>
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon far icon='smile' className='fa-fw me-3' />
<span className='sidenav-non-slim'>Link 7</span>
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon far icon='smile' className='fa-fw me-3' />
<span className='sidenav-non-slim'>Link 8</span>
</MDBSideNavLink>
</MDBSideNavItem>
</MDBScrollbar>
<div className='text-center' style={{ minHeight: '3rem' }}>
<hr className='mt-0 mb-2' />
<small>mdbootstrap.com</small>
</div>
</MDBSideNav>
<div style={{ padding: '20px' }} className='text-center'>
<MDBBtn onClick={() => setInnerOpen(!innerOpen)}>
<MDBIcon fas icon='bars' />
</MDBBtn>
</div>
</>
);
}
Full-screen examples
The following examples show various settings of the side navigation component in a full-screen mode.
2. Side navigation with a mode transition
Resize the window to change the mode from side
to over
.
import React, { useState, useRef, useEffect, useCallback } from 'react';
import {
MDBSideNav,
MDBSideNavMenu,
MDBSideNavItem,
MDBSideNavLink,
MDBSideNavCollapse,
MDBIcon,
} from 'mdb-react-ui-kit';
export default function App() {
const [basicCollapse1, setBasicCollapse1] = useState(true);
const [basicCollapse2, setBasicCollapse2] = useState(true);
const [mode, setMode] = useState('side');
const contentRef = useRef(null);
const handleResize = useCallback(() => {
if (window.matchMedia('(min-width: 900px)')) {
return setMode('side');
}
return setMode('push');
}, []);
useEffect(() => {
window.addEventListener('resize', handleResize);
return () => {
window.removeEventListener('resize', handleResize);
};
}, [handleResize]);
return (
<>
<MDBSideNav backdrop={false} mode={mode} color='dark' closeOnEsc={false}>
<div className='mt-4'>
<div id='header-content' className='ps-3'>
<img
src='https://mdbootstrap.com/img/Photos/Avatars/img%20(23).webp'
alt='avatar'
className='rounded-circle img-fluid mb-3'
style={{ maxWidth: '50px' }}
/>
<h4>
<span style={{ whiteSpace: 'nowrap' }}>Ann Smith</span>
</h4>
<p>ann_s@mdbootstrap.com</p>
</div>
<hr className='mb-0' />
</div>
<MDBSideNavMenu>
<MDBSideNavItem>
<MDBSideNavLink href='/'>
<MDBIcon icon='envelope' className='fas fa-fw me-3' />
Inbox
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon icon='paper-plane' className='fas fa-fw me-3' />
Outbox
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink icon='address-book' onClick={() => setBasicCollapse1(!basicCollapse1)}>
Contacts
</MDBSideNavLink>
<MDBSideNavCollapse show={basicCollapse1}>
<MDBSideNavLink>Family</MDBSideNavLink>
<MDBSideNavLink>Friends</MDBSideNavLink>
<MDBSideNavLink>Work</MDBSideNavLink>
</MDBSideNavCollapse>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon icon='file' className='fas fa-fw me-3' />
Drafts
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon icon='heart' className='fas fa-fw me-3' />
Favourites
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon icon='star' className='fas fa-fw me-3' />
Starred
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon icon='trash' className='fas fa-fw me-3' />
Trash
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon icon='ban' className='fas fa-fw me-3' />
Spam
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink icon='tag' onClick={() => setBasicCollapse2(!basicCollapse2)}>
Contacts
</MDBSideNavLink>
<MDBSideNavCollapse show={basicCollapse2}>
<MDBSideNavLink>Social</MDBSideNavLink>
<MDBSideNavLink>Notifications</MDBSideNavLink>
<MDBSideNavLink>Recent</MDBSideNavLink>
<MDBSideNavLink>Uploads</MDBSideNavLink>
<MDBSideNavLink>Backups</MDBSideNavLink>
<MDBSideNavLink>Offers</MDBSideNavLink>
</MDBSideNavCollapse>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon icon='sticky-note' className='fas fa-fw me-3' />
Notes
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon icon='user-circle' className='fas fa-fw me-3' />
Personal
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon icon='ellipsis-h' className='fas fa-fw me-3' />
More
</MDBSideNavLink>
</MDBSideNavItem>
</MDBSideNavMenu>
<hr className='m-0' />
<MDBSideNavMenu>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon icon='cogs' className='fas fa-fw me-3' />
Settings
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon icon='user' className='fas fa-fw me-3' />
Profile
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon icon='shield-alt' className='fas fa-fw me-3' />
Privacy
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem>
<MDBSideNavLink>
<MDBIcon icon='user-astronaut' className='fas fa-fw me-3' />
Logout
</MDBSideNavLink>
</MDBSideNavItem>
</MDBSideNavMenu>
<div className='text-center' style={{ height: '100px' }}>
<hr className='mb-4 mt-0' />
<p>MDBootstrap.com</p>
</div>
</MDBSideNav>
<div
style={{ width: '100%', height: '100vh', paddingLeft: '240px', transition: 'padding 0.3s linear' }}
className='text-center bg-light'
ref={contentRef}
>
<div className='text-center py-5'>
<h3 className='my-5'>Resize to change the mode</h3>
<div>
<img
className='rounded'
style={{ maxWidth: '80%' }}
src='https://mdbootstrap.com/img/Photos/Others/img%20(53).webp'
/>
</div>
</div>
</div>
</>
);
}
3. Slim side navigation (dark)
Non-expandable slim sidenav with a dark background and custom width.
import React, { useRef } from 'react';
import { MDBSideNav, MDBSideNavMenu, MDBSideNavItem, MDBSideNavLink, MDBIcon } from 'mdb-react-ui-kit';
export default function App() {
const contentRef = useRef(null);
return (
<>
<MDBSideNav backdrop={false} color='dark' closeOnEsc={false} slim slimCollapsed bgColor='dark'>
<div className='text-center mt-4'>
<a className='ripple rounded-circle' data-mdb-color='light' href='#'>
<img
src='https://mdbootstrap.com/img/Photos/Avatars/img%20(29).webp'
alt='avatar'
className='rounded-circle img-fluid'
style={{ maxWidth: '60px' }}
/>
</a>
</div>
<hr />
<MDBSideNavMenu>
<MDBSideNavItem className='my-3'>
<MDBSideNavLink className='p-0 d-flex justify-content-center'>
<MDBIcon far icon='heart' size='2x'></MDBIcon>
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem className='my-3'>
<MDBSideNavLink className='p-0 d-flex justify-content-center'>
<MDBIcon far icon='envelope' size='2x'></MDBIcon>
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem className='my-3'>
<MDBSideNavLink className='p-0 d-flex justify-content-center'>
<MDBIcon far icon='user' size='2x'></MDBIcon>
</MDBSideNavLink>
</MDBSideNavItem>
<MDBSideNavItem className='my-3'>
<MDBSideNavLink className='p-0 d-flex justify-content-center'>
<MDBIcon icon='cogs' size='2x'></MDBIcon>
</MDBSideNavLink>
</MDBSideNavItem>
</MDBSideNavMenu>
</MDBSideNav>
<div ref={contentRef} className='page-intro'>
<div className='mask p-4 text-center'>
<h1>Natalie Smith</h1>
<h2>Portfolio</h2>
</div>
</div>
</>
);
}
.sidenav[data-mdb-slim-width='90'] {
width: 90px;
}
.page-intro {
background-image: url('https://mdbcdn.b-cdn.net/img/Photos/Others/img%20(52).webp');
background-size: cover;
background-position-x: center;
background-color: white;
width: 100vw;
height: 100vh;
}
.mask {
background-color: rgba(66, 66, 66, 0.4);
width: 100%;
height: 100%;
color: rgba(255, 255, 255, 0.8);
}
.mask h1 {
margin-top: 220px;
font-size: 6rem;
}
.mask h2 {
font-size: 2.8rem;
}
@media (max-width: 500px) {
.mask h1 {
font-size: 4rem;
}
.mask h2 {
font-size: 2rem;
}
}
Drawer - API
Import
import {
MDBSideNav,
MDBSideNavMenu,
MDBSideNavItem,
MDBSideNavLink,
MDBSideNavCollapse
} from 'mdb-react-ui-kit';