Fidely UI v1 beta is now available!. 🚀

Dialog

A modal window that appears on top of the main content.

Usage

import { Dialog } from '@fidely-ui/react'
<Dialog.Root>
  <Dialog.Trigger />
  <Dialog.Backdrop />
  <Dialog.Positioner>
    <Dialog.Content>
      <Dialog.CloseTrigger />
      <Dialog.Header>
        <Dialog.Title />
      </Dialog.Header>
      <Dialog.Body />
      <Dialog.Footer />
    </Dialog.Content>
  </Dialog.Positioner>
</Dialog.Root>

Examples

Sizes

Use the size prop to change the size of the dialog component.

Controlled

Use the open and onOpenChange prop to control the visibility of the dialog component.

Within Context

Use the Dialog.Context component to access the dialog state and methods from outside the dialog.

Store

An alternative way to control the dialog is to use the RootProvider component and the useDialog store hook.

This way you can access the dialog state and methods from outside the dialog.

AlertDialog

By default dialog renders as role: "dialog" to change the role below

Pass the role: "alertdialog" prop to change the dialog component to an alert dialog.

Initial Focus

Use the initialFocusEl prop to set the initial focus of the dialog component.

Props

Root

PropTypeDefaultDescription
defaultOpenbooleanfalseThe initial open state of the dialog when rendered. Use when you don't need to control the open state of the dialog.
closeOnEscapebooleantrueWhether to close the dialog when the escape key is pressed
closeOnInteractOutsidebooleantrueWhether to close the dialog when the outside is clicked
lazyMountbooleanfalseWhether to enable lazy mounting
modalbooleantrueWhether to prevent pointer interaction outside the element and hide all content below it.
preventScrollbooleantrueWhether to prevent scrolling behind the dialog when it's opened
role"dialog" | "alertdialog""dialog"The dialog's role.
size "xs" | "sm" | "md" | "lg""md"Controls the size of the switch.
skipAnimationOnMount`boolean"false"Whether to allow the initial presence animation.
unmountOnExitbooleanfalseWhether to unmount on exit.
trapFocusbooleantrueWhether to trap focus inside the dialog when it's opened.
asReact.ElementType—The content of the switch, typically including control, thumb, and label.
finalFocusEl() => MaybeElement—Element to receive focus when the dialog is closed
idstring—The unique identifier of the machine.
idsPartial<{ trigger: string positioner: string backdrop: string content: string closeTrigger: string title: string description: string }>—The ids of the elements in the dialog. Useful for composition.
immediateboolean—Whether to synchronize the present change immediately or defer it to the next frame.
openboolean—The controlled open state of the dialog.
presentboolean—Whether the node is present (controlled by the user).
persistentElementsboolean—Returns the persistent elements that: - should not have pointer-events disabled - should not trigger the dismiss event.
restoreFocusboolean—Whether to restore focus to the element that had focus before the dialog was opened

CloseTrigger

PropTypeDefaultDescription
asChildfalsebooleanUse the provided child element as the default rendered element, combining their props and behavior.

On this page