Synertech Web/ui v0.57.5 Site Storybook

Documentation / Layout

Drawer

Client@synertech/uiOpen in Storybook

A panel that slides in from an edge of the screen (left, right, top, bottom) over the page: an edit form, a cart, filters, the detail of a row. It is always controlled: the application holds open and closes it in onClose, called by the close button, the Escape key and a click on the overlay.

It is a true modal dialog: role="dialog" and aria-modal, focus moves into the panel when it opens, Tab stays trapped inside, the rest of the page becomes inert and focus returns to the trigger on close. title gives it its accessible name; without a title, pass aria-label. The close button is only rendered with a title, and its label comes from UILabelsProvider (or closeLabel). Rendered in a portal on document.body, the component is marked "use client".

Examples

Basic usage

A title and some content; Escape, the close button or the overlay call onClose.

Open in a tab
import { useState } from "react";
import { Button, Drawer } from "@synertech/ui";

export function Basic() {
  const [open, setOpen] = useState(false);

  return (
    <>
      <Button onClick={() => setOpen(true)}>Voir les notifications</Button>
      <Drawer open={open} onClose={() => setOpen(false)} title="Notifications">
        <p className="text-sm text-gray-600 dark:text-gray-300">Aucune nouvelle notification.</p>
      </Drawer>
    </>
  );
}

Position and size

position picks the edge, size the width (or the height for top / bottom); customWidth / customHeight accept any CSS value.

Open in a tab
import { useState } from "react";
import { Button, Drawer } from "@synertech/ui";

export function Positions() {
  const [position, setPosition] = useState<"left" | "bottom" | null>(null);

  return (
    <div className="flex gap-3">
      <Button onClick={() => setPosition("left")}>Menu à gauche</Button>
      <Button onClick={() => setPosition("bottom")}>Panneau en bas</Button>
      <Drawer
        open={position !== null}
        onClose={() => setPosition(null)}
        position={position ?? "left"}
        size="sm"
        customHeight={position === "bottom" ? "40vh" : undefined}
        title={position === "left" ? "Navigation" : "Détails"}
      >
        <p className="text-sm">Contenu du panneau.</p>
      </Drawer>
    </div>
  );
}

Edit form with an action footer

footer stays pinned below the scrolling content; initialFocus puts the cursor straight into the first field.

Open in a tab
import { useRef, useState } from "react";
import { Button, Drawer, Input } from "@synertech/ui";

export function EditForm() {
  const [open, setOpen] = useState(false);
  const nameRef = useRef<HTMLInputElement>(null);
  const close = () => setOpen(false);

  return (
    <>
      <Button onClick={() => setOpen(true)}>Modifier le client</Button>
      <Drawer
        open={open}
        onClose={close}
        size="lg"
        title="Modifier le client"
        initialFocus={nameRef}
        footer={
          <div className="flex justify-end gap-2">
            <Button
              onClick={close}
              bgColor="bg-gray-100 hover:bg-gray-200"
              textColor="text-gray-800"
            >
              Annuler
            </Button>
            <Button type="submit" form="client-form">
              Enregistrer
            </Button>
          </div>
        }
      >
        <form
          id="client-form"
          className="space-y-4"
          onSubmit={(event) => {
            event.preventDefault();
            close();
          }}
        >
          <Input ref={nameRef} label="Raison sociale" defaultValue="Atelier Dupont" />
          <Input label="E-mail de facturation" type="email" defaultValue="compta@dupont.fr" />
        </form>
      </Drawer>
    </>
  );
}

Filters panel without a title

Without title, name the panel with aria-label and provide your own close button. closeOnOverlayClick={false} avoids losing input to an accidental click.

Open in a tab
import { useState } from "react";
import { Button, Checkbox, Drawer } from "@synertech/ui";

export function FiltersPanel() {
  const [open, setOpen] = useState(false);

  return (
    <>
      <Button onClick={() => setOpen(true)}>Filtres</Button>
      <Drawer
        open={open}
        onClose={() => setOpen(false)}
        position="left"
        aria-label="Filtres"
        closeOnOverlayClick={false}
        footer={
          <Button fullWidth onClick={() => setOpen(false)}>
            Appliquer les filtres
          </Button>
        }
      >
        <fieldset className="space-y-2">
          <legend className="mb-2 font-medium">Statut</legend>
          <Checkbox label="Payée" />
          <Checkbox label="En attente" />
          <Checkbox label="En retard" />
        </fieldset>
      </Drawer>
    </>
  );
}

API reference

Components

Drawer

ComponentClient
import { Drawer } from "@synertech/ui";

Props — DrawerProps

PropTypeDefaultDescription
children• ReactNode —
onClose• () => void —
open• boolean —
aria-label string —

Accessible name of the drawer when no title is rendered. A dialog without a name is announced as "dialog" only, so provide one of the two.

className string —
closeLabel string —

Accessible name of the close button. Defaults to the closeDrawer label of the nearest UILabelsProvider.

closeOnEscape boolean true
closeOnOverlayClick boolean true
customHeight string —

Custom height of the drawer (e.g. "400px", "25rem", "40%"). Takes precedence over size for the top/bottom positions.

customWidth string —

Custom width of the drawer (e.g. "400px", "25rem", "40%"). Takes precedence over size for the left/right positions.

initialFocus DialogInitialFocus —

Element focused when the drawer opens. Default "dialog".

lockScroll boolean true

Prevent the page behind the drawer from scrolling. Default true.

overlayClassName string —
position DrawerPosition "right"
returnFocus DialogReturnFocus —

Element focused when the drawer closes. Default true (the trigger).

showOverlay boolean true
size DrawerSize "md"
title string —
trapFocus boolean true

Keep Tab / Shift+Tab inside the drawer. Default true.

Types

type DrawerPosition = "left" | "right" | "top" | "bottom"
type DrawerSize = "sm" | "md" | "lg" | "xl" | "full" | "half"