Dialog

stable 3.8 kB
<hk-dialog>

Built on the native <dialog> element, so focus trapping, Escape, inertness of the page behind and the top layer all come from the platform rather than a JavaScript reimplementation.

#modal#popup

Live demo

Running in this page — interact with it.

Inputs

NameTypeDefaultDescription
closeOnBackdropbooleantrueClicking the backdrop dismisses.
size'sm' | 'md' | 'lg''md'Panel width.

Outputs

  • closedEventEmitter<string>

    Emits the return value, or "dismissed".

Methods

  • open()() => void

    Opens as a modal and moves focus inside.

  • close(value?)(value?: string) => void

    Closes and returns the value through (closed).

Keyboard

  • Escape Closes — handled by the platform
  • Tab Cycles within the dialog only

Theming

Component tokens, each falling back to a global one:

PropertyDefaultControls
--hk-dialog-bg#ffffffPanel background.
--hk-dialog-backdroprgb(15 23 42 / 0.5)Backdrop wash.
--hk-dialog-width22remDefault panel width.

Accessibility

  • showModal() gives real focus trapping and marks the rest of the page inert; no focus-loop code to get wrong.
  • Focus returns to the invoking element on close.
  • The panel is labelled by its title element via aria-labelledby.

More in Overlay