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
element for proper screen reader support<dialog> - Focus Management: Automatically focuses elements with
attribute, or the modal content itselfautofocus - Focus Restoration: Can restore focus to the triggering element when closed using the
proptriggeredBy - Keyboard Navigation: Supports ESC key to close the modal
- ARIA Attributes: Includes
when a title is providedaria-labelledby - 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
prop that renders a sticky action bar at the bottom of the Modalactions - Added Dark Mode support