Tailwind CSS Drawer (offcanvas) - Flowbite
The Drawer component can be used as a hidden off-canvas sidebar for navigation and to show other information based on multiple styles and placements
Use the Drawer component (or “off-canvas”) to show a fixed element relative to the document page from any side for navigation, contact forms, informational purposes or other user actions.
You can set multiple options such as the placement, activate body scrolling, show or hide the backdrop and even use the swipeable edge functionality to show a small part of the drawer when it is not shown completely.
To enable interactivity via data attributes and the Drawer API you need to include Flowbite’s JavaScript file.
Default drawer #
To initiate the drawer component you need to set the data-drawer-target="{id}" data attribute to an element such as a button where the value needs to be the id of the drawer component itself.
Then you can use the following attributes to either show, hide or toggle the drawer visibility where the value is the id of the drawer component:
data-drawer-show="{id}"- show the drawer componentdata-drawer-hide="{id}"- hide the drawer componentdata-drawer-toggle="{id}"- toggle the visibility of the drawer component
For accessibility you should also apply the aria-controls={id} attribute to the element that triggers the drawer and the aria-labelledby={id} attribute to the drawer component where the value is the id of the drawer title.
You can also avoid the drawer flickering and hide it by default by applying the following classes to the Drawer element: transition-transform left-0 top-0 -translate-x-full. This will set the component off-canvas.