Skip to content
Focsd homeFocsd homeFocsd
Forms

Dialog

A modal dialog for a focused decision. The title asks the question; the body states the consequence.

  • Tag: focsd-dialog
  • Pattern: Dialog (modal)
  • Category: Overlays

Example

Remove member

Lukas loses access to 8 projects immediately. Their files stay in the workspace.

Keep member Remove Lukas
HTML
<focsd-button commandfor="dialog-demo" command="show-modal">Remove member</focsd-button>
<focsd-dialog id="dialog-demo" headline="Remove Lukas Brandt?">
<p>Lukas loses access to 8 projects immediately. Their files stay in the workspace.</p>
<focsd-button slot="actions" data-dialog-close value="keep">Keep member</focsd-button>
<focsd-button slot="actions" variant="critical" data-dialog-close value="remove"
>Remove Lukas</focsd-button
>
</focsd-dialog>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/components/focsd-dialog.js';
</script>
<focsd-dialog headline="Remove Lukas Brandt?">…</focsd-dialog>

API

Attributes

AttributePropertyTypeDefault
headlineheadlinestring—
openopenbooleanfalse
closedbyclosedBy'any' | 'closerequest' | 'none'closerequest
no-closenoClosebooleanfalse

Methods

MethodDescription
show(opener)Open as a modal dialog. Focus returns to opener (default: the element focused now) on close, which matters in Safari where clicking a button does not focus it.
showModal(opener)Same as show(): Focsd dialogs are always modal.
requestClose(returnValue)Ask to close: fires a cancelable cancel, then closes with returnValue unless it was canceled.
close(returnValue)Close, optionally setting returnValue.

Events

EventDescription
cancelFired before a close request (Escape, backdrop, requestClose); cancel it to keep the dialog open.
closeFired after the dialog closes; read returnValue for how it closed.

Slots

SlotDescription
(default)Default content.
actionsThe dialog's buttons.

CSS parts

Style the inside of the component with ::part(), for example focsd-dialog::part(actions).

PartDescription
actionsThe actions element.
bodyThe body element.
closeThe close (×) button, last in the tab order; it asks to close like Escape (hidden with `no-close`).
dialogThe dialog element.
headlineThe headline element.

Accessibility

  • requestClose() and Escape fire a cancelable cancel; showModal() is an alias of show(). closedby="any" also closes on a backdrop click; closedby="none" needs an explicit close action.
  • Built on native <dialog>.showModal(): top layer, inert background, Escape to close.
  • A close (×) button named "Close" sits in the top corner and asks to close as Escape does (a cancelable cancel). It comes last in the tab order, so opening the dialog focuses its content first. Add no-close for a dialog that must be answered with one of its actions.
  • Open it from a button with no script: <focsd-button commandfor="dialog-id" command="show-modal">. Focus returns to that button on close. From your own code, call show(opener).
  • Any slotted element with data-dialog-close closes it; its value becomes returnValue. Put data-autofocus on the element that should receive focus first.

Keyboard

KeyAction
TabMoves focus within the dialog; the page behind is inert
EscapeCloses (unless closedby="none")