Primitiveoverlay

Dialog

Stable

Overlay modal com trigger, título, descrição, corpo rolável, rodapé e fechamento. Composto sobre Base UI Dialog e sobre o Button do Up Web DS.

Instalação

npx up-web-ds add dialog

Gera close para a biblioteca de ícones do projeto (components.json → iconLibrary).

Preview

Default

Destructive

With Form

Disable Overlay Close

Scrollable Content

Without Close Button

With Status

All states

Default

Destructive

With Form

Disable Overlay Close

Scrollable Content

Without Close Button

With Status

Usage

Imports de Dialog
import {
  Dialog,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from '@/components/ui/dialog'
import { Button } from '@/components/ui/button'
Dialog
<Dialog>
  <DialogTrigger render={<Button variant="outline" />}>
    Abrir dialog
  </DialogTrigger>

  <DialogContent>
    <DialogHeader>
      <DialogTitle>Publicar no registry</DialogTitle>
      <DialogDescription>
        O item passa a ficar disponível para os projetos da equipe via{' '}
        <code className="font-mono">npx shadcn@latest add</code>.
      </DialogDescription>
    </DialogHeader>

    <DialogFooter>
      <DialogClose render={<Button variant="outline" />}>
        Cancelar
      </DialogClose>
      <DialogClose render={<Button />}>Publicar</DialogClose>
    </DialogFooter>
  </DialogContent>
</Dialog>

Props

Dialog

Props de Dialog
PropTypeDefaultDescription
disableOverlayClosebooleanfalseLocks dismissal to the dialog's own close actions: a press on the overlay and the Escape key no longer close it, only a `DialogClose` (the footer's Cancelar, the popup's close button) or a controlled `open` does. For a dialog whose content would be lost if it closed by accident, such as a half-filled form.
actionsRefReact.RefObject<DialogRootActions | null>sem valor padrãoA ref to imperative actions. - `unmount`: Manually unmounts the dialog. Call this after any externally controlled closing animation finishes. - `close`: Closes the dialog imperatively when called.
childrenReact.ReactNode | PayloadChildRenderFunction<unknown>sem valor padrãoThe content of the dialog. This can be a regular React node or a render function that receives the `payload` of the active trigger.
defaultOpenbooleanfalseWhether the dialog is initially open. To render a controlled dialog, use the `open` prop instead.
defaultTriggerIdstring | nullsem valor padrãoID of the trigger that the dialog is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open dialog.
disablePointerDismissalbooleanfalseWhether to prevent the dialog from closing on outside presses. For non-modal dialogs, this also prevents the dialog from closing when focus moves outside of it.
handleDialogHandle<unknown>sem valor padrãoA handle to associate the dialog with a trigger. If specified, allows external triggers to control the dialog's open state. Can be created with the Dialog.createHandle() method.
modalboolean | "trap-focus"trueDetermines if the dialog enters a modal state when open. - `true`: user interaction is limited to just the dialog: 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 dialog, but document page scroll is not locked and pointer interactions outside of it remain enabled. When `modal` is `true` or `'trap-focus'`, render `<Dialog.Close>` inside `<Dialog.Popup>` so touch screen readers can escape the popup.
onOpenChange((open: boolean, eventDetails: DialogRoot.ChangeEventDetails) => void)sem valor padrãoEvent handler called when the dialog is opened or closed.
onOpenChangeComplete((open: boolean) => void)sem valor padrãoEvent handler called after any animations complete when the dialog is opened or closed.
openbooleansem valor padrãoWhether the dialog is currently open.
triggerIdstring | nullsem valor padrãoID of the trigger that the dialog is associated with. This is useful in conjunction with the `open` prop to create a controlled dialog. There's no need to specify this prop when the dialog is uncontrolled (that is, when the `open` prop is not set).

Estende DialogPrimitive.Root.Props.

DialogTrigger

Props de DialogTrigger
PropTypeDefaultDescription
classNamestring | ((state: DialogTriggerState) => string | undefined)sem valor padrãoCSS class applied to the element, or a function that returns a class based on the component's state.
handleDialogHandle<unknown>sem valor padrãoA handle to associate the trigger with a dialog. Can be created with the Dialog.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 the dialog in controlled mode (with the DialogRoot `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 dialog when it is opened.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DialogTriggerState>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: DialogTriggerState) => 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 DialogPrimitive.Trigger.Props. Aceita também os atributos padrão de um elemento React (284 não listados).

DialogPortal

Props de DialogPortal
PropTypeDefaultDescription
classNamestring | ((state: DialogPortalState) => 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, DialogPortalState>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: DialogPortalState) => 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 DialogPrimitive.Portal.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

DialogClose

Props de DialogClose
PropTypeDefaultDescription
classNamestring | ((state: DialogCloseState) => 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, DialogCloseState>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: DialogCloseState) => 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 DialogPrimitive.Close.Props. Aceita também os atributos padrão de um elemento React (285 não listados).

DialogOverlay

Props de DialogOverlay
PropTypeDefaultDescription
classNamestring | ((state: DialogBackdropState) => 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, DialogBackdropState>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: DialogBackdropState) => 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 DialogPrimitive.Backdrop.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

DialogPopup

Props de DialogPopup
PropTypeDefaultDescription
showCloseButtonbooleantrue
classNamestring | ((state: DialogPopupState) => 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 dialog 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, `null` to fall back to 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 dialog is opened. By default, focus moves to the first tabbable element inside the popup, except when the dialog is opened by touch — then the popup itself is focused to avoid opening the virtual keyboard. - `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, `null` to fall back to the default behavior, or `false`/`undefined` to do nothing.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DialogPopupState>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: DialogPopupState) => 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 DialogPopupProps. Aceita também os atributos padrão de um elemento React (275 não listados).

DialogViewport

Props de DialogViewport
PropTypeDefaultDescription
classNamestring | ((state: DialogViewportState) => 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, DialogViewportState>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: DialogViewportState) => 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 DialogPrimitive.Viewport.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

DialogContent

Props de DialogContent
PropTypeDefaultDescription
overlayClassNamestringsem valor padrãoAdditional presentation classes for the backdrop created by `DialogContent`. This lets recipes customise the visual treatment of the overlay while keeping portal, modal semantics, focus management and interaction behaviour owned by the Dialog primitive.
showCloseButtonbooleansem valor padrão
classNamestring | ((state: DialogPopupState) => 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 dialog 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, `null` to fall back to 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 dialog is opened. By default, focus moves to the first tabbable element inside the popup, except when the dialog is opened by touch — then the popup itself is focused to avoid opening the virtual keyboard. - `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, `null` to fall back to the default behavior, or `false`/`undefined` to do nothing.
renderReact.ReactElement<unknown, string | React.JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, DialogPopupState>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: DialogPopupState) => 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 DialogContentProps. Aceita também os atributos padrão de um elemento React (275 não listados).

DialogHeader

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

DialogBody

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

DialogTitle

Props de DialogTitle
PropTypeDefaultDescription
classNamestring | ((state: DialogTitleState) => 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, DialogTitleState>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: DialogTitleState) => 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 DialogPrimitive.Title.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

DialogDescription

Props de DialogDescription
PropTypeDefaultDescription
classNamestring | ((state: DialogDescriptionState) => 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, DialogDescriptionState>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: DialogDescriptionState) => 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 DialogPrimitive.Description.Props. Aceita também os atributos padrão de um elemento React (275 não listados).

Composition

Gatilho e conteúdo são irmãos. O DialogClose pode estar em qualquer lugar dentro do conteúdo; no rodapé é onde ele vira ação.

Composição de Dialog

Dialog

  • DialogTrigger
  • DialogContent
    • DialogHeader
      • DialogTitle
      • DialogDescription
    • DialogBody
    • DialogFooter
      • DialogClose

Metadata

Notas de acessibilidade

Teclado e leitor de tela verificados por teste: abre pelo trigger e pelo teclado, fecha com Escape e por DialogClose, e é nomeado/descrito por DialogTitle e DialogDescription. Touch verificado em viewport de 375px com emulação de toque: alvos de 32x32 (fechar) e 293x36 (ação do rodapé), acima do mínimo de 24x24 da WCAG 2.2 SC 2.5.8; abrir, rolar o corpo, fechar pela ação e descartar pelo backdrop funcionam por toque. Reduced motion verificado em navegador com prefers-reduced-motion: reduce: o zoom de entrada e saída é aplicado em motion-safe:, então sob reduce o popup aparece sem escala; o animate-in, o fade e a duração continuam incondicionais, porque é o animationend deles que o Base UI espera para desmontar. Verificado nos dois modos: abre, fecha, o foco entra e volta ao gatilho, e o popup não fica preso em opacidade parcial nem em transform intermediário.

Classificação

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

Origem e distribuição

Fonte
shadcn registry / dialog
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
close
Construído sobre
Button