Skip to content

Dialog ​

A modal dialog for a question or a short form, as a compound component on Base UI's dialog. For one question with a typed answer, use PromptDialog.

tsx
import { Dialog } from '@adecore/ui';
tsx
import { Button, Dialog } from '@adecore/ui';
import { useState } from 'react';

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

    return (
        <Dialog.Root open={open} onOpenChange={setOpen}>
            <Dialog.Trigger render={<Button variant="danger-outline" />}>Remove branch</Dialog.Trigger>
            <Dialog.Popup size="sm">
                <Dialog.Title>Remove the branch?</Dialog.Title>
                <Dialog.Description className="mt-1">It has two commits nothing else has.</Dialog.Description>
                <Dialog.Text size="xs" className="mt-2">
                    A removed branch can be restored from the reflog for 90 days.
                </Dialog.Text>
                <Dialog.Footer>
                    <Dialog.Close render={<Button />}>Cancel</Dialog.Close>
                    <Button variant="danger" onClick={() => setOpen(false)}>
                        Remove
                    </Button>
                </Dialog.Footer>
            </Dialog.Popup>
        </Dialog.Root>
    );
}

Parts ​

PartWhat it is
Dialog.RootHolds the open state: open and onOpenChange, or defaultOpen.
Dialog.TriggerThe button that opens it.
Dialog.PopupThe portal, the backdrop and the popup in one part.
Dialog.TitleThe heading and accessible name. size="lg" for a header rather than a question.
Dialog.DescriptionThe sentence under the title, read as the dialog's description. No margin.
Dialog.TextAnother line in the description's style, such as a warning.
Dialog.FooterThe buttons, main action last (on the right).
Dialog.CloseA button that closes the dialog. Pass a Button through render.

Size ​

size="sm" is 420 pixels wide with 20 pixels of padding, for question dialogs. Without a size, className sets the width and there is no padding.

A dialog over a dialog ​

A dialog opened over another stacks over it and dims it. nested forces that layering for a dialog that always opens over another. Menus and selects in either dialog float above both.

tsx
import { Button, Dialog } from '@adecore/ui';

export default function DialogNested() {
    return (
        <Dialog.Root>
            <Dialog.Trigger render={<Button variant="secondary" />}>Edit profile</Dialog.Trigger>
            <Dialog.Popup className="w-[480px] p-5">
                <Dialog.Title size="lg">Profile</Dialog.Title>
                <Dialog.Description className="mt-1">A dialog opened from inside another one stacks over it and dims it.</Dialog.Description>
                <Dialog.Footer>
                    <Dialog.Root>
                        <Dialog.Trigger render={<Button variant="danger-outline" />}>Delete account</Dialog.Trigger>
                        <Dialog.Popup size="sm">
                            <Dialog.Title>Delete the account?</Dialog.Title>
                            <Dialog.Description className="mt-1">Everything in it goes with it.</Dialog.Description>
                            <Dialog.Footer>
                                <Dialog.Close render={<Button />}>Keep it</Dialog.Close>
                                <Dialog.Close render={<Button variant="danger" />}>Delete</Dialog.Close>
                            </Dialog.Footer>
                        </Dialog.Popup>
                    </Dialog.Root>
                    <Dialog.Close render={<Button variant="primary" />}>Done</Dialog.Close>
                </Dialog.Footer>
            </Dialog.Popup>
        </Dialog.Root>
    );
}

Dialog.Popup takes Base UI's popup props, plus:

PropTypeDefault
size'sm'
nestedbooleanfalseAlways over another dialog.
backdropbooleantrueThe dim behind the dialog.
backdropClassNamestringSuch as lightbox-backdrop, a heavier dim for a picture.
keepMountedbooleanKeeps the popup mounted while closed.

Dialog.Title takes size 'base' (the default) or 'lg'. Dialog.Description and Dialog.Text take size 'sm' (the default) or 'xs'. Dialog.Text and Dialog.Footer take render.

Keyboard and focus ​

Focus moves into the dialog and Tab stays inside. Escape and a backdrop click call onOpenChange(false). Closing returns focus to the trigger.

Types ​

DialogPopupProps, DialogTitleProps, DialogDescriptionProps, DialogTextProps and DialogFooterProps are exported types.

Licenses and third-party notices are listed in each package.