Drawer

free

Drawer brings supporting panels into the current page without a route change.

import { useState } from 'react';
import Button from '@/components/ui/button';
import Drawer from '@/components/ui/drawer';

Installation

Add this component with the NateUI CLI.

npx nateui@latest add Drawer

Examples

Basic

import { useState } from 'react';
import Button from '@/components/ui/button';
import Drawer from '@/components/ui/drawer';

Placement

import { useState } from 'react';
import Button from '@/components/ui/button';
import Drawer from '@/components/ui/drawer';
import Radio from '@/components/ui/radio';

Width & Height

import { useState } from 'react';
import Button from '@/components/ui/button';
import Drawer from '@/components/ui/drawer';
import { useState } from 'react';
import Button from '@/components/ui/button';
import Drawer from '@/components/ui/drawer';

Custom Style

import { useState } from 'react';
import Button from '@/components/ui/button';
import Drawer from '@/components/ui/drawer';

Closable

import { useState } from 'react';
import Button from '@/components/ui/button';
import Drawer from '@/components/ui/drawer';

Custom Backdrop

import { useState } from 'react';
import Button from '@/components/ui/button';
import Drawer from '@/components/ui/drawer';

Form

import { useState } from 'react';
import Button from '@/components/ui/button';
import Drawer from '@/components/ui/drawer';
import Form from '@/components/ui/form';

API

Drawer accepts the props below plus native props for the drawer content div.

PropDescriptionTypeDefault
bodyClassExtra class names applied to the scrollable body region.string-
childrenContent rendered in the scrollable body of the drawer.ReactNode-
closableShows the default close button in the header.booleantrue
contentClassNameClass names applied to the drawer content surface.string-
footerContent rendered in a footer region below the body.string | ReactNode-
footerClassExtra class names applied to the footer region.string-
headerClassExtra class names applied to the header region.string-
heightHeight of the drawer. Used when placement is 'top' or 'bottom'.string | number370
isOpenControls whether the drawer is visible.booleanfalse
lockScrollLocks document scrolling through the overlay while the drawer is mounted.booleantrue
onCloseCalled when the drawer asks to close through the close button, overlay, Escape key, or a drag-to-dismiss gesture.DrawerOpenChangeHandler-
onOpenCalled when the floating layer reports that the drawer opened.DrawerOpenChangeHandler-
overlayClassNameClass names applied to the overlay element.string-
placementEdge the drawer slides out from. 'top' and 'bottom' add a drag handle for dismissing the drawer by swipe.DrawerPlacement'right'
refRef forwarded to the drawer content element.Ref<HTMLDivElement>-
shouldCloseOnEscAllows Escape to request closing the drawer.booleantrue
shouldCloseOnOverlayClickAllows an overlay click to request closing the drawer.booleantrue
titleTitle rendered in the header region.string | ReactNode-
widthWidth of the drawer. Used when placement is 'left' or 'right'.number370
...nativeDivPropsNative props applied to the drawer content element.NativeDrawerDivProps-

Types

type DrawerPlacement = 'top' | 'right' | 'bottom' | 'left';
type DrawerOpenChangeHandler = (open: boolean) => void;
type NativeDrawerDivProps = Omit<ComponentProps<'div'>, 'title'>;