For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/en/llms-full.txt, and this page is available as Markdown at https://ifhover.github.io/leaf-ui/en/components/drawer.md.

Drawer

Open content from a page edge to view details or complete an action.

Basic usage

Handle onClose and update open in the application. Provide aria-label when omitting title.

basic.tsx
import { Button, Drawer, Paragraph } from '@ifhover/leaf-ui';
import { useState } from 'react';

export function DrawerBasic() {
  const [open, setOpen] = useState(false);
  return (
    <>
      <Button onClick={() => setOpen(true)}>View details</Button>
      <Drawer open={open} title="Document details" onClose={() => setOpen(false)}>
        <Paragraph>
          This document is maintained by the design team and was last updated this week.
        </Paragraph>
      </Drawer>
    </>
  );
}

Examples

Placement

Use width for left and right drawers, and height for top and bottom drawers.

placement.tsx
import { Button, Drawer, type DrawerProps, Paragraph, Space } from '@ifhover/leaf-ui';
import { useState } from 'react';

const placements = [
  { value: 'left', label: 'Left' },
  { value: 'right', label: 'Right' },
  { value: 'top', label: 'Top' },
  { value: 'bottom', label: 'Bottom' },
] as const;

export function DrawerPlacement() {
  const [open, setOpen] = useState(false);
  const [placement, setPlacement] = useState<DrawerProps['placement']>('right');
  return (
    <>
      <Space wrap>
        {placements.map((item) => (
          <Button
            key={item.value}
            onClick={() => {
              setPlacement(item.value);
              setOpen(true);
            }}
          >
            {item.label}
          </Button>
        ))}
      </Space>
      <Drawer
        open={open}
        placement={placement}
        title="Document details"
        onClose={() => setOpen(false)}
      >
        <Paragraph>View details from the selected edge of the page.</Paragraph>
      </Drawer>
    </>
  );
}

Associate the footer submit button with the form using its form attribute to retain native validation. Submission and closing are handled by the application.

sections.tsx
import { Button, Drawer, Form, FormField, Input, Space } from '@ifhover/leaf-ui';
import { useId, useState } from 'react';

export function DrawerSections() {
  const [open, setOpen] = useState(false);
  const formId = useId();
  return (
    <>
      <Button onClick={() => setOpen(true)}>Edit name</Button>
      <Drawer
        open={open}
        title="Edit name"
        onClose={() => setOpen(false)}
        footer={
          <Space wrap>
            <Button onClick={() => setOpen(false)}>Cancel</Button>
            <Button variant="solid" type="submit" form={formId}>
              Save
            </Button>
          </Space>
        }
      >
        <Form
          id={formId}
          layout="vertical"
          onSubmit={(event) => {
            event.preventDefault();
            setOpen(false);
          }}
        >
          <FormField label="Name" required>
            <Input name="name" defaultValue="Leaf UI" />
          </FormField>
        </Form>
      </Drawer>
    </>
  );
}

Resizing

Enable resizable to drag the edge or focus the separator and use arrow keys. minSize and maxSize limit the resize value reported by onResize; the visible size remains constrained by the viewport. Changing width or height resets the manual adjustment.

resize.tsx
import { Button, Drawer, Text } from '@ifhover/leaf-ui';
import { useState } from 'react';

export function DrawerResize() {
  const [open, setOpen] = useState(false);
  const [size, setSize] = useState<number>();
  return (
    <>
      <Button onClick={() => setOpen(true)}>Resize the drawer</Button>
      <Drawer
        open={open}
        title="Resize"
        onClose={() => setOpen(false)}
        resizable
        minSize={260}
        maxSize={640}
        onResize={setSize}
      >
        <Text tone="muted" role="status">
          {size == null ? 'Not resized yet' : `Resized to: ${size}px`}
        </Text>
      </Drawer>
    </>
  );
}

Nested push

Set push on the child drawer to shift its nearest parent overlay. true means 40px, or pass a distance directly. Escape closes only the topmost drawer, then focus returns to its opener. Reset the child's open when closing the parent to avoid reopening both layers.

nested.tsx
import { Button, Drawer, Paragraph } from '@ifhover/leaf-ui';
import { useState } from 'react';

export function DrawerNested() {
  const [open, setOpen] = useState(false);
  const [childOpen, setChildOpen] = useState(false);
  const closeParent = () => {
    setChildOpen(false);
    setOpen(false);
  };
  return (
    <>
      <Button onClick={() => setOpen(true)}>Open first drawer</Button>
      <Drawer open={open} title="First drawer" onClose={closeParent}>
        <Button onClick={() => setChildOpen(true)}>Open second drawer</Button>
        <Drawer
          open={childOpen}
          title="Second drawer"
          width={300}
          push
          onClose={() => setChildOpen(false)}
        >
          <Paragraph>This is the content of the second drawer.</Paragraph>
        </Drawer>
      </Drawer>
    </>
  );
}

Tabbed drawer

Use tabs to embed line tabs beneath the heading or in place of it when untitled. The tab bar stays fixed above the scrolling body and always keeps its bottom divider even when divided={false} (the default). Omit item children when using the tabs solely to switch state for Drawer's children.

tabs.tsx
import { Button, Drawer, Text } from '@ifhover/leaf-ui';
import { useState } from 'react';

export function DrawerTabs() {
  const [open, setOpen] = useState(false);
  const [view, setView] = useState('overview');
  return (
    <>
      <Button onClick={() => setOpen(true)}>Inspect details</Button>
      <Drawer
        open={open}
        title="Task details"
        onClose={() => setOpen(false)}
        tabs={{
          activeKey: view,
          onChange: setView,
          items: [
            { key: 'overview', label: 'Overview' },
            { key: 'logs', label: 'Logs' },
          ],
        }}
      >
        <Text>
          {view === 'overview'
            ? 'Omit item children to use the tab bar as a view switcher for the drawer body.'
            : 'Showing the logs view while keeping the tab bar divider visible.'}
        </Text>
      </Drawer>
    </>
  );
}

For content preservation and focus configuration, see Modal advanced usage.

API

Drawer API

Configuration for controlled visibility, placement, content regions and dismissal.

PropertyTypeDefaultDescription
openbooleanRequiredControlled open state, updated by the application.
titleReactNode—Drawer title.
descriptionReactNode—Additional description.
tabsDrawerTabsProps—Embedded tabs; replace the heading when untitled or sit beneath it, retaining the tab bar bottom divider.
onClose() => void—Close request; update open in application state
placement'left' | 'right' | 'top' | 'bottom''right'Opening edge
widthnumber | string380Width for left and right drawers
heightnumber | string300Height for top and bottom drawers
footerReactNode—Footer content
extraReactNode—Actions beside the title
iconReactNode—Decorative icon to the left of the heading.
dividedbooleanfalseSeparate the heading, content and footer with subtle borders.
closablebooleantrueShow the close button.
maskClosablebooleantrueRequest closing when the mask is clicked.
keyboardbooleantrueAllow Escape to request closing.
initialFocusRefObject<HTMLElement | null> | (() => HTMLElement | null)—Specify initial focus after opening.
returnFocusboolean | RefObject<HTMLElement | null> | (() => HTMLElement | null)—Restore focus on close; specify a destination or use false.
resizablebooleanfalseAllow resizing by dragging or arrow keys.
minSizenumber240Minimum size in pixels.
maxSizenumber900Maximum size in pixels.
onResize(size: number) => void—Return the new size on pointer or keyboard resizing; changing width or height resets the manual size.
pushboolean | numberfalsePush the nearest parent overlay; true uses 40px and a number specifies the distance.
afterClose() => void—Called after the closing transition
destroyOnClosebooleanfalseUnmount contents after closing; preserve takes precedence and forceRender keeps contents mounted.
preserveboolean—Control content preservation, taking precedence over destroyOnClose; does not reset external controlled state.
forceRenderbooleanfalseMount before opening and keep hidden while closed.
containerElement | DocumentFragment | (() => Element | DocumentFragment)—Portal mount target; may also return a ShadowRoot.

DrawerTabs API

See the Tabs API (opens in a new tab) for embedded tab props. Drawer fixes type="line" and placement="top", keeps the tab bar fixed above the scrollable body with its bottom divider always visible regardless of divided={false}, and restores an ordinary drawer when items is empty.

type DrawerTabsProps = Omit<TabsProps, 'type' | 'placement' | 'children'>;