Dialog
A modal window that holds focus until it closes.
The dialog opens in the browser’s top layer, so it needs no portal. DialogHeader and
DialogFooter are layout helpers; the title and description name and describe it for
screen readers.
Dependencies
What it's built from and what's built from it in Mocha, read from the imports in its source.
| Uses | Scroll AreaprimitiveTextprimitive |
|---|---|
| Used by | Nothing yet. |
| Packages | @ui-sdk/core@0.1.0-beta.20@ui-sdk/react@0.1.0-beta.20 |
Installation
Set the project up for Mocha once first, as Getting started shows. Then add it with the CLI, or by hand.
With the CLI
Manually
Install its packages:
Add the components it uses first, listed under Dependencies.
Then copy the source:
API reference
Generated from Mocha's types. Props marked ours are added here; the rest come from the ui-sdk part it wraps. Every part also accepts its element's native attributes.
DialogBackdrop
Dims the page behind an open dialog.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: DialogBackdropState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: DialogBackdropState) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<DialogBackdropState>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: DialogBackdropState) => CSSProperties)
DialogContent
The dialog itself. Give it a DialogTitle, and a DialogClose unless it has its own way out.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: DialogContentState<unknown>) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: DialogContentState<unknown>) => string)
- container
Renders the popup into this element instead of in place, like a container inside a shadow root or an iframe. On web components, a CSS selector. Nested popups stay inside their parent.
Type Element | DocumentFragment | null
- finalFocus
Where focus goes when the dialog closes while focus is inside it.
Type PopupFocusTarget · Default "trigger"
- initialFocus
Where focus goes when the dialog opens. Opening with touch focuses the dialog itself, so no on-screen keyboard appears, unless this is set to something other than
"auto".Type DialogInitialFocus · Default "auto"
- inline
Renders the dialog and its backdrop where they are in the page instead of above it, so it can stay inside a frame, like an app preview. Pair it with
modal="trap-focus"to keep the rest of the page usable. Acontaineron the dialog still moves its backdrop, so leave it off.Type boolean · Default false
- keepMounted
Whether the dialog stays in the page, hidden, while closed. Its content keeps its state between opens.
Type boolean · Default false
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<DialogContentState<unknown>>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: DialogContentState<unknown>) => CSSProperties)
DialogDescription
Describes the dialog, read out when it opens.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: {}) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: {}) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<{}>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: {}) => CSSProperties)
DialogFooter
Holds the dialog's actions, last one first on small screens.
Takes the props of a native div.
DialogHeader
Groups the title and description at the top of a dialog.
Takes the props of a native div.
DialogTitle
Names the dialog.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: {}) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: {}) => string)
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<{}>
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: {}) => CSSProperties)
DialogTrigger
The button that opens the dialog. A trigger outside the dialog, like one per table row, connects through controller.
- children
Content, or a function of the part's state that returns it.
Type ReactNode | ((state: DialogTriggerState) => ReactNode)
- className
Class names, or a function of the part's state that returns them.
Type string | ((state: DialogTriggerState) => string)
- controller
Connects a trigger outside the dialog, like one per table row, to the dialog with this controller.
Type PopupController<any, DialogOpenChangeReason, {}, any, DialogPayloadChangeReason>
- disabled
Stops presses. The button is natively disabled, so it leaves the tab order and its form doesn't submit through it, unless
focusableWhenDisabledis set.Type boolean · Default false
- focusableWhenDisabled
Keeps a disabled trigger in the tab order with
aria-disabledinstead of the native attribute, so it can host a tooltip that says why. Presses still do nothing.Type boolean · Default false
- payload
Data for the content to render when this trigger opens the dialog, like the row it belongs to.
Type unknown
- render
Renders your own element: one that receives the part's props, or a function of the props and the state.
Type RenderProp<DialogTriggerState>
- shortcut
A keyboard shortcut that presses the trigger, like
"mod+k".modis Command on Apple platforms and Control elsewhere. Setsaria-keyshortcuts, and a Shortcut part inside shows it. A modal dialog pauses the page's shortcuts while it's open.Type string
- style
Styles, or a function of the part's state that returns them.
Type CSSProperties | ((state: DialogTriggerState) => CSSProperties)