Sidenav
React Bootstrap 5 Sidenav component
The side navigation component provides an easy way to navigate through your website. Its appearance & behaviour are easily adjustable properties - additional functionality.
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>
</>
);
}
Sidenav - API
Import
import {
MDBSideNav,
MDBSideNavMenu,
MDBSideNavItem,
MDBSideNavLink,
MDBSideNavCollapse
} from 'mdb-react-ui-kit';