Modal
Displays content in an overlay. Use to create a distraction-free experience such as a confirmation dialog or a settings panel.
Anchor to propertiesProperties
- Anchor to accessibilityLabelaccessibilityLabelstring
A label that describes the purpose of the modal. When set, it will be announced to users using assistive technologies and will provide them with more context.
This overrides the
heading
prop for screen readers.- Anchor to headingheadingstring
A title that describes the content of the Modal.
- Anchor to hideOverlayhideOverlay() => void
Method to hide an overlay.
- Anchor to paddingpadding"base" | "none"
Adjust the padding around the Modal content.
base
: applies padding that is appropriate for the element.none
: removes all padding from the element. This can be useful when elements inside the Modal need to span to the edge of the Modal. For example, a full-width image. In this case, rely onBox
with a padding of 'base' to bring back the desired padding for the rest of the content.- Anchor to showOverlayshowOverlay() => void
Method to show an overlay.
- Anchor to sizesize"small" | "small-100" | "base" | "large" | "large-100"
Adjust the size of the Modal.
- Anchor to toggleOverlaytoggleOverlay() => void
Method to toggle the visiblity of an overlay.
Anchor to eventsEvents
Learn more about registering events.
- Anchor to afterhideafterhideCallbackEventListener<typeof tagName> | null
- Anchor to aftershowaftershowCallbackEventListener<typeof tagName> | null
- Anchor to hidehideCallbackEventListener<typeof tagName> | null
- Anchor to showshowCallbackEventListener<typeof tagName> | null
CallbackEventListener
(EventListener & {
(event: CallbackEvent<T>): void;
}) | null
CallbackEvent
Event & {
currentTarget: HTMLElementTagNameMap[T];
}
Anchor to slotsSlots
- Anchor to primary-actionprimary-actionHTMLElement
The primary action to perform.
Only a
Button
with a variant ofprimary
is allowed.- Anchor to secondary-actionssecondary-actionsHTMLElement
The secondary actions to perform.
Only
or
Button
with a variant ofsecondary
orauto
are allowed.
Code
Examples
Code
Default
<s-button commandFor="modal"> Open </s-button> <s-modal id="modal" heading="Details"> <s-paragraph> Displaying more details here. </s-paragraph> <s-button slot="secondary-actions" commandFor="modal" command="--hide"> Close </s-button> <s-button slot="primary-action" variant="primary" commandFor="modal" command="--hide"> Save </s-button> </s-modal>