Primitiveoverlay

Drawer

Stable

Superfície de borda que se pega: acompanha o dedo um para um, assenta proporcional à força do gesto, empilha quando outra abre por cima e para em snap points. Composto sobre Base UI Drawer. O Sheet e o Drawer ancoram na mesma borda, e escolher entre eles não é gosto — a camada de gesto só se paga quando o toque é a via principal; fora disso o Sheet é a resposta honesta.

Instalação

npx up-web-ds add drawer

Preview

Default

Variants

Without Overlay

With Snap Points

Directions Default

Directions Inset

Non Modal

All states

Default

Variants

Without Overlay

With Snap Points

Directions Default

Directions Inset

Non Modal

Usage

Imports de Drawer
import {
  Drawer,
  DrawerBody,
  DrawerClose,
  DrawerContent,
  DrawerDescription,
  DrawerFooter,
  DrawerHeader,
  DrawerTitle,
  DrawerTrigger,
} from '@/components/ui/drawer'
import { Button } from '@/components/ui/button'
Drawer
<Drawer showSwipeHandle>
  <DrawerTrigger render={<Button variant="outline" />}>
    Abrir detalhes
  </DrawerTrigger>
  <DrawerContent>
    <DrawerHeader>
      <DrawerTitle>primitives/drawer</DrawerTitle>
      <DrawerDescription>
        Superfície que segue o dedo. Arraste para baixo para dispensar, ou
        use o botão abaixo.
      </DrawerDescription>
    </DrawerHeader>
    <DrawerBody>
      <dl className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5 type-small">
        {[
          ['Type', 'primitive'],
          ['Category', 'overlay'],
          ['Domain', 'null'],
          ['Fonte', 'shadcn/ui'],
          ['Licença', 'MIT'],
        ].map(([term, value]) => (
          <div key={term} className="contents">
            <dt className="text-muted-foreground">{term}</dt>
            <dd className="font-mono type-caption">{value}</dd>
          </div>
        ))}
      </dl>
    </DrawerBody>
    <DrawerFooter>
      <DrawerClose render={<Button variant="outline" />}>
        Fechar
      </DrawerClose>
    </DrawerFooter>
  </DrawerContent>
</Drawer>

Props

Drawer

Props de Drawer
PropTypeDefaultDescription
showSwipeHandlebooleanfalse
actionsRefReact.RefObject<DrawerRootActions | null>sem valor padrãoA ref to imperative actions. - `unmount`: Manually unmounts the drawer. Call this after any externally controlled closing animation finishes. - `close`: Closes the drawer imperatively when called.
childrenReact.ReactNode | PayloadChildRenderFunction<unknown>sem valor padrãoThe content of the drawer.
defaultOpenbooleanfalseWhether the drawer is initially open. To render a controlled drawer, use the `open` prop instead.
defaultSnapPointDrawerSnapPoint | nullsem valor padrãoThe initial snap point value when uncontrolled.
defaultTriggerIdstring | nullsem valor padrãoID of the trigger that the drawer is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open drawer.
disablePointerDismissalbooleanfalseWhether to prevent the drawer from closing on outside presses. For non-modal drawers, this also prevents the drawer from closing when focus moves outside of it.
handleDrawerHandle<unknown>sem valor padrãoA handle to associate the drawer with a trigger. If specified, allows detached triggers to control the drawer's open state. Can be created with the Drawer.createHandle() method.
modalboolean | "trap-focus"trueDetermines if the drawer enters a modal state when open. - `true`: user interaction is limited to just the drawer: focus is trapped, document page scroll is locked, and pointer interactions on outside elements are disabled. - `false`: user interaction with the rest of the document is allowed. - `'trap-focus'`: focus is trapped inside the drawer, but document page scroll is not locked and pointer interactions outside of it remain enabled.
onOpenChange((open: boolean, eventDetails: DrawerRoot.ChangeEventDetails) => void)sem valor padrãoEvent handler called when the drawer is opened or closed.
onOpenChangeComplete((open: boolean) => void)sem valor padrãoEvent handler called after any animations complete when the drawer is opened or closed.
onSnapPointChange((snapPoint: DrawerSnapPoint | null, eventDetails: DrawerRoot.SnapPointChangeEventDetails) => void)sem valor padrãoCallback fired when the snap point changes.
openbooleansem valor padrãoWhether the drawer is currently open.
snapPointDrawerSnapPoint | nullsem valor padrãoThe currently active snap point. Use with `onSnapPointChange` to control the snap point.
snapPointsDrawerSnapPoint[]sem valor padrãoSnap points used to position the drawer. Use numbers between 0 and 1 to represent fractions of the viewport height, numbers greater than 1 as pixel values, or strings in `px`/`rem` units (for example, `'148px'` or `'30rem'`).
snapToSequentialPointsbooleanfalseDisables velocity-based snap skipping so drag distance determines the next snap point.
swipeDirectionSwipeDirection'down'The swipe direction used to dismiss the drawer.
triggerIdstring | nullsem valor padrãoID of the trigger that the drawer is associated with. This is useful in conjunction with the `open` prop to create a controlled drawer. There's no need to specify this prop when the drawer is uncontrolled (that is, when the `open` prop is not set).

Estende DrawerPrimitive.Root.Props.

DrawerTrigger

Props de DrawerTrigger
PropTypeDefaultDescription
classNamestring | ((state: DrawerTriggerState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
handleDrawerHandle<unknown>sem valor padrãoA handle to associate the trigger with a drawer. Can be created with the Drawer.createHandle() method.
idstringsem valor padrãoID of the trigger. In addition to being forwarded to the rendered element, it is also used to specify the active trigger for drawers in controlled mode (with the Drawer.Root `triggerId` prop).
nativeButtonbooleantrueWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`).
payloadunknownsem valor padrãoA payload to pass to the drawer when it is opened.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DrawerTriggerState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: DrawerTriggerState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende DrawerPrimitive.Trigger.Props. Aceita também os atributos padrão de um elemento React (284 não listados).

DrawerPortal

Props de DrawerPortal
PropTypeDefaultDescription
classNamestring | ((state: DrawerPortalState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
containerHTMLElement | ShadowRoot | React.RefObject<HTMLElement | ShadowRoot | null> | nullsem valor padrãoA parent element to render the portal element into.
keepMountedbooleanfalseWhether to keep the portal mounted in the DOM while the popup is hidden.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DrawerPortalState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: DrawerPortalState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende DrawerPrimitive.Portal.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

DrawerClose

Props de DrawerClose
PropTypeDefaultDescription
classNamestring | ((state: DrawerCloseState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
nativeButtonbooleantrueWhether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`).
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DrawerCloseState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: DrawerCloseState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende DrawerPrimitive.Close.Props. Aceita também os atributos padrão de um elemento React (285 não listados).

DrawerOverlay

Props de DrawerOverlay
PropTypeDefaultDescription
classNamestring | ((state: DrawerBackdropState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
forceRenderbooleanfalseWhether the backdrop is forced to render even when nested.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DrawerBackdropState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: DrawerBackdropState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende DrawerPrimitive.Backdrop.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

DrawerSwipeHandle

Estende React.ComponentProps<'div'>. Aceita também os atributos padrão de um elemento React (280 não listados).

DrawerContent

Props de DrawerContent
PropTypeDefaultDescription
showOverlaybooleantrueWhether to render the visual scrim behind a modal drawer.
variant"default" | "inset"'default'Whether the panel meets its edge or floats inside the viewport.
classNamestring | ((state: DrawerPopupState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
finalFocusboolean | React.RefObject<HTMLElement | null> | ((closeType: InteractionType) => boolean | HTMLElement | null | void)sem valor padrãoDetermines the element to focus when the drawer is closed. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (trigger or previously focused element). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, or `false`/`undefined` to do nothing.
initialFocusboolean | React.RefObject<HTMLElement | null> | ((openType: InteractionType) => boolean | HTMLElement | null | void)sem valor padrãoDetermines the element to focus when the drawer is opened. - `false`: Do not move focus. - `true`: Move focus based on the default behavior (first tabbable element or popup). - `RefObject`: Move focus to the ref element. - `function`: Called with the interaction type (`mouse`, `touch`, `pen`, or `keyboard`). Return an element to focus, `true` to use the default behavior, or `false`/`undefined` to do nothing.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DrawerPopupState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: DrawerPopupState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende DrawerPrimitive.Popup.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

DrawerHeader

Estende React.ComponentProps<'div'>. Aceita também os atributos padrão de um elemento React (280 não listados).

DrawerBody

Estende React.ComponentProps<'div'>. Aceita também os atributos padrão de um elemento React (280 não listados).

DrawerTitle

Props de DrawerTitle
PropTypeDefaultDescription
classNamestring | ((state: DrawerTitleState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DrawerTitleState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: DrawerTitleState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende DrawerPrimitive.Title.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

DrawerDescription

Props de DrawerDescription
PropTypeDefaultDescription
classNamestring | ((state: DrawerDescriptionState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DrawerDescriptionState>sem valor padrãoAllows you to replace the component's HTML element with a different tag, or compose it with another component. Accepts a `ReactElement` or a function that returns the element to render.
styleReact.CSSProperties | ((state: DrawerDescriptionState) => React.CSSProperties | undefined)sem valor padrãoStyle applied to the element, or a function that returns a style object based on the component's state.

Estende DrawerPrimitive.Description.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

Composition

A mesma estrutura do Dialog, mais a alça de arrasto que o Drawer precisa por percorrer o viewport.

Composição de Drawer

Drawer

  • DrawerTrigger
  • DrawerContent
    • DrawerSwipeHandle
    • DrawerHeader
      • DrawerTitle
      • DrawerDescription
    • DrawerBody
    • DrawerFooter
      • DrawerClose

Metadata

Notas de acessibilidade

Teclado verificado por teste: o foco entra na superfície ao abrir, Tab dá a volta dentro dela enquanto o drawer é modal, Escape fecha devolvendo o foco ao gatilho, e o controle nomeado do rodapé faz por teclado e ponteiro o que o gesto faz por toque — uma superfície cuja única saída é arrastar é uma superfície que algumas pessoas não conseguem fechar. Leitor de tela verificado por teste: o drawer é nomeado pelo DrawerTitle e descrito pelo DrawerDescription, a alça de arraste é aria-hidden por ser afordância de um gesto que o leitor de tela não executa, e o modo não modal não desenha scrim porque a página atrás continua utilizável. Touch verificado em navegador com emulação de toque em viewport de 375px: o arraste dispensa a superfície, o corpo rola com overscroll-contain para que chegar ao fim da lista não vire dispensa acidental, e os alvos medem acima do mínimo de 24x24 da WCAG 2.2 SC 2.5.8. Reduced motion verificado com prefers-reduced-motion: reduce — o painel percorre um viewport inteiro e o transform dele é o que o Base UI observa, então a transição é encurtada (motion-reduce:duration-fast) em vez de removida: tirar a transição tiraria junto o transitionend que desmonta o drawer e quebraria o arraste. O deslocamento fica curto, e abrir, fechar e responder ao gesto continuam intactos.

Classificação

Layer
Primitive
Domínio
Domain-free (compartilhado)
Categoria
overlay
Status
Stable

Origem e distribuição

Fonte
shadcn registry / drawer
Licença
MIT
Distribuição
Interna

Acessibilidade

  • Teclado: revisado
  • Leitor de tela: revisado
  • Touch: revisado
  • Reduced motion: revisado

Dependências

Pacotes
@base-ui/react
Ícones
Nenhum
Construído sobre
Nenhum
Usado por
Nenhum ainda