eds-modal

Explore the Interactive Component

Use the playground below to experiment with the component. Click the button to view the full Storybook deployment for additional examples and configurations.

eds-modal Open in Storybook

See It in Use with Code

Check out this practical implementation of component.

Anything you place inside <eds-modal> is rendered in its default slot as the modal body. Open and close it with the open(), close() and toggle() methods; it emits edsopen and edsclose.

Plain HTML

In React

In Vue

Sizes and Position

sizeWidthUse for
small500pxConfirmations, short messages
medium700px (default)Forms, detailed content
large900pxComplex layouts, tables

position is middle (default), top or bottom on larger screens. On phones the modal is always full width at the top. Put actions in slot="footer": secondary first, primary last.

Overview

EdsModal is a dialog for focused tasks and messages, built on the native <dialog> element (showModal()), so the browser keeps keyboard and screen-reader focus inside it and makes the page behind inert.

  • Light header with title, optional subtitle and a close button (inverse-header for the brand-black header).
  • Body scrolls; an optional footer slot stays pinned at the bottom.
  • Closes on Escape, the close button or a click on the backdrop, unless dismissible is false (for flows that must be finished or cancelled with an explicit action).
  • Open it with open() / toggle(), the opened prop, or the eds-modal-open event; it returns focus to where it was on close.
  • On phones it is full width, anchored to the top.

Properties

PropertyAttributeDescriptionTypeDefault
dismissibledismissibleWhether the user can dismiss the modal with Escape, the close button or a click on the backdrop. Set to false when the modal must be finished or cancelled with an explicit action in its content or footer; the close button is then hidden.booleantrue
headingtitleThe title of the modal. Names the dialog for assistive technology.string''
initialFocusinitial-focusCSS selector of the element to focus when the modal opens, looked up in the modal’s content (e.g. #email). Defaults to the first focusable element in the content, then the close button.stringundefined
inverseHeaderinverse-headerBrand-black header with light text instead of the default light header.booleanfalse
openedopenedDeclarative open state: set it to open or close the modal. Kept in sync when the modal opens or closes by other means (reflected as the opened attribute). open(), close() and toggle() still work.booleanfalse
positionpositionWhere the modal sits on larger screens: "middle" (default), "top" or "bottom". On phones it is always full width at the top."bottom" | "middle" | "top"'middle'
sizesizeWidth of the modal (it keeps this width while its content loads): "small" 500px, "medium" 700px (default), "large" 900px — never wider than the screen."large" | "medium" | "small"'medium'
subtitlesubtitleOptional secondary line under the title, in lighter text (e.g. a file path or the item the modal is about). Describes the dialog.stringundefined
truncatetruncateThe number of lines to truncate the title to. Set to 0 or undefined to disable truncation.0 | 1 | 2 | 3 | 4undefined

Events

EventDescriptionType
edscloseEmitted when the modal closes, however it was closed — the close button, Escape, the backdrop, close()/toggle(), opened = false or the global eds-modal-close event. Lets a caller discard work started in the modal that was not saved.CustomEvent<void>
edsopenEmitted when the modal opens.CustomEvent<void>

Methods

close() => Promise<void>

Closes the modal.

Returns

Type: Promise<void>

open() => Promise<void>

Opens the modal.

Returns

Type: Promise<void>

toggle() => Promise<void>

Toggles the modal open or closed.

Returns

Type: Promise<void>

Dependencies

Depends on

Graph

graph TD;
  eds-modal --> eds-button
  eds-button --> eds-icon-wrapper
  style eds-modal fill:#f9f,stroke:#333,stroke-width:4px

Built with StencilJS