Use our Tailwind CSS drawer for side menus in your website.
See below our simple Drawer
example that you can use in your Tailwind CSS and React project.
Material Tailwind features multiple React and HTML components, all written with Tailwind CSS classes and Material Design guidelines.
You can change the position of the Drawer
component using the placement
prop.
Use this beautiful and versatile example to display navigation options in a hidden panel that can be accessed by clicking a button. These components are usually used in various apps and systems.
Similar to the previous example, this drawer will display a form instead of displaying navigation options.
The following props are available for drawer component. These are the custom props that we've added for the drawer component and you can use all the other native props as well.Navigation
Attribute | Type | Description | Default |
---|---|---|---|
open | boolean | Sets the open and close state of drawer | No default value it's a required prop. |
size | number | Set's the width/height of the drawer depending on the drawer placement | 250 |
placement | Placement | Sets the drawer placement | left |
overlay | boolean | Sets the overlay visibility for the drawer | true |
overlayRef | Overlay Ref | Add reference for the drawer overlay | undefined |
overlayProps | Overlay Props | Sets the rest props for the drawer overlay | undefined |
dismiss | dismiss | Change dismiss listeners for drawer | undefined |
onClose | function | Sets the callback function for closing the drawer | undefined |
transition | Framer Motion | Sets the transition for drawer |
|
className | string | Add custom className for drawer | '' |
children | node | Add content for drawer | No default value it's a required prop. |
import type { DrawerProps } from "@material-tailwind/react";
export type placement = "top" | "right" | "bottom" | "left";
export type overlayRef = React.Ref<HTMLDivElement>;
export type overlayProps = React.ComponentProps<"div">;
type dismissType = {
enabled?: boolean;
escapeKey?: boolean;
referencePress?: boolean;
referencePressEvent?: "pointerdown" | "mousedown" | "click";
outsidePress?: boolean | ((event: MouseEvent) => boolean);
outsidePressEvent?: "pointerdown" | "mousedown" | "click";
ancestorScroll?: boolean;
bubbles?:
| boolean
| {
escapeKey?: boolean;
outsidePress?: boolean;
};
};
Learn how to customize the theme and styles for drawer component, the theme object for drawer component has two main objects:
A. The defaultProps
object for setting up the default value for props of drawer component.
B. The styles
object for customizing the theme and styles of drawer component.
You can customize the theme and styles of drawer component by adding Tailwind CSS classes as key paired values for objects.
interface DrawerStylesType {
defaultProps: {
size: number;
overlay: boolean;
placement: "top" | "right" | "bottom" | "left";
overlayProps: React.ClassAttributes<HTMLDivElement> & React.HTMLAttributes<HTMLDivElement>;
className: string;
dismiss: {
enabled: boolean;
escapeKey: boolean;
referencePress: boolean;
referencePressEvent: 'pointerdown' | 'mousedown' | 'click';
outsidePress: boolean | ((event: MouseEvent) => boolean);
outsidePressEvent: 'pointerdown' | 'mousedown' | 'click';
ancestorScroll: boolean;
bubbles: boolean | {
escapeKey: boolean;
outsidePress: boolean;
};
};
onClose: () => void;
transition: object;
};
styles: {
base: {
container: object;
overlay: object;
drawer: object;
};
};
}
import { DrawerStylesType } from "@material-tailwind/react";
const theme = {
drawer: {
defaultProps: {
size: 300,
overlay: true,
placement: "left",
overlayProps: undefined,
className: "",
dismiss: undefined,
onClose: undefined,
transition: {
type: "tween",
duration: 0.3,
},
},
styles: {
base: {
drawer: {
position: "fixed",
zIndex: "z-[9999]",
pointerEvents: "pointer-events-auto",
backgroundColor: "bg-white",
boxSizing: "box-border",
width: "w-full",
boxShadow: "shadow-2xl shadow-blue-gray-900/10",
},
overlay: {
position: "absolute",
inset: "inset-0",
width: "w-full",
height: "h-full",
pointerEvents: "pointer-events-auto",
zIndex: "z-[9995]",
backgroundColor: "bg-black",
backgroundOpacity: "bg-opacity-60",
backdropBlur: "backdrop-blur-sm",
},
},
},
},
};