Modal

Dark Mode
Accessibility

A conditional modal component with built-in accessibility features.

Props

Name
Type
Default
Description
actions
array
A list of actions rendered in the action bar.
children
element
The content of the modal.
onClose
func
A listener that is called once clicked outside of the modal.
secondaryAction
func
A secondary Action in the header of the modal.
title
string
Sets the title of the modal.
triggeredByRef
object
A ref to the element that triggered the modal. Focus will be restored to this element when the modal closes.
useDialog
bool
Force using dialog element (true) or overlay fallback (false). Defaults to browser support detection.
visible
bool
Sets the visiblity of the modal.
zIndex
number
Sets the zIndex of the modal.

Accessibility

The Modal component includes several accessibility features:

  • Semantic HTML: Uses the native
    <dialog>
    element for proper screen reader support
  • Focus Management: Automatically focuses elements with
    autofocus
    attribute, or the modal content itself
  • Focus Restoration: Can restore focus to the triggering element when closed using the
    triggeredBy
    prop
  • Keyboard Navigation: Supports ESC key to close the modal
  • ARIA Attributes: Includes
    aria-labelledby
    when a title is provided
  • Click Outside to Close: Users can click outside the modal to close it
  • Proper Focus Trapping: Focus remains within the modal while it's open

Examples

Actions

Nested Modals

Fallback Implementation

The Modal component automatically detects browser support for the native

<dialog>
element and falls back to an overlay-based implementation for older browsers. You can also manually force the fallback behavior using the
useDialog
prop.

Changelog

03. Nov 2021

  • Updated layout according to the latest design
  • Introducing the
    actions
    prop that renders a sticky action bar at the bottom of the Modal
  • Added Dark Mode support