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
headingprop 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"Default: 'base'
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 onBoxwith 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"Default: 'base'
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;
}) | nullCallbackEvent
Event & {
currentTarget: HTMLElementTagNameMap[T];
}Anchor to slotsSlots
- Anchor to childrenchildrenHTMLElement
The content of the Modal.
- Anchor to primary-actionprimary-actionHTMLElement
The primary action to perform.
Only a
Buttonwith a variant ofprimaryis allowed.- Anchor to secondary-actionssecondary-actionsHTMLElement
The secondary actions to perform.
Only
Buttonelements with a variant ofsecondaryorautoare allowed.
Code
Preview
Examples
Code
jsx
<> <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> </>html
<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>
Anchor to usageUsage
Modals are closed by default and should be triggered by a button using the attribute. The button's value should match the modal's id.
Anchor to useful-forUseful for
- Focusing on a specific task or piece of information
- Completing a flow that needs dedicated attention
- Confirming a significant action before proceeding
- Viewing information that's only temporarily relevant
Anchor to best-practicesBest practices
- Use for focused, specific tasks that require merchants to make a decision or acknowledge critical information
- Include a prominent and clear call to action
- Don't nest modals (avoid launching one modal from another)
- Have concise and descriptive title and button text
- Use thoughtfully and sparingly—don't create unnecessary interruptions
- Use as a last resort for important decisions, not for contextual tools or actions that could happen on the page directly
Anchor to content-guidelinesContent guidelines
- Use 1-3 word titles in sentence case without punctuation
- Keep body content to 1-2 short sentences
- For destructive actions, explain the consequences
- Use clear action verbs for buttons (e.g., "Delete", "Edit") instead of vague language like "Yes" or "OK"
Anchor to examplesExamples
Component examples
Anchor to example-basic-usageBasic usage
Anchor to example-basic-modalBasic modal
Simple modal with heading and basic content for displaying information. Click the button to open the modal.
Anchor to example-modal-with-actionsModal with actions
Modal with primary and secondary action buttons. Click the button to open the confirmation modal.
Anchor to example-modal-with-form-fieldsModal with form fields
Modal containing form fields demonstrating how to structure input fields within a modal. Click the button to open the modal.
Anchor to example-different-modal-sizesDifferent modal sizes
Demonstrates various modal sizes for different content requirements. Click each button to see different modal sizes.
Anchor to example-modal-without-paddingModal without padding
Modal with no padding for full-width content. Click to view the modal.
Basic modal
Preview
Examples
Basic modal
Description
Simple modal with heading and basic content for displaying information. Click the button to open the modal.
jsx
<> <s-button commandFor="info-modal" command="--show"> Show product info </s-button> <s-modal id="info-modal" heading="Product information"> <s-text> This product is currently out of stock and cannot be ordered. </s-text> <s-button slot="secondary-actions" commandFor="info-modal" command="--hide"> Close </s-button> </s-modal> </>html
<s-button commandFor="info-modal" command="--show">Show product info</s-button> <s-modal id="info-modal" heading="Product information"> <s-text>This product is currently out of stock and cannot be ordered.</s-text> <s-button slot="secondary-actions" commandFor="info-modal" command="--hide"> Close </s-button> </s-modal>Modal with actions
Description
Modal with primary and secondary action buttons. Click the button to open the confirmation modal.
jsx
<s-stack gap="base"> <s-button tone="critical" commandFor="delete-modal" command="--show"> Delete product </s-button> <s-modal id="delete-modal" heading="Delete product?"> <s-stack gap="base"> <s-text>Are you sure you want to delete "Winter jacket"?</s-text> <s-text tone="caution">This action cannot be undone.</s-text> </s-stack> <s-button slot="primary-action" variant="primary" tone="critical" commandFor="delete-modal" command="--hide" > Delete product </s-button> <s-button slot="secondary-actions" variant="secondary" commandFor="delete-modal" command="--hide" > Cancel </s-button> </s-modal> </s-stack>html
<s-stack gap="base"> <s-button tone="critical" commandFor="delete-modal" command="--show"> Delete product </s-button> <s-modal id="delete-modal" heading="Delete product?"> <s-stack gap="base"> <s-text>Are you sure you want to delete "Winter jacket"?</s-text> <s-text tone="caution">This action cannot be undone.</s-text> </s-stack> <s-button slot="primary-action" variant="primary" tone="critical" commandFor="delete-modal" command="--hide" > Delete product </s-button> <s-button slot="secondary-actions" variant="secondary" commandFor="delete-modal" command="--hide" > Cancel </s-button> </s-modal> </s-stack>Modal with form fields
Description
Modal containing form fields demonstrating how to structure input fields within a modal. Click the button to open the modal.
jsx
<s-stack gap="base"> <s-button variant="primary" commandFor="edit-modal" command="--show"> Edit customer </s-button> <s-modal id="edit-modal" heading="Edit customer information" size="large"> <s-stack gap="base"> <s-text-field label="Customer name" name="name" value="Sarah Johnson" /> <s-email-field label="Email address" name="email" value="sarah@example.com" /> <s-text-field label="Phone number" name="phone" value="+1 555-0123" /> <s-select label="Customer group" name="group"> <s-option value="retail">Retail</s-option> <s-option value="wholesale" selected> Wholesale </s-option> <s-option value="vip">VIP</s-option> </s-select> </s-stack> <s-button slot="primary-action" variant="primary" commandFor="edit-modal" command="--hide" > Save changes </s-button> <s-button slot="secondary-actions" variant="secondary" commandFor="edit-modal" command="--hide" > Cancel </s-button> </s-modal> </s-stack>html
<s-stack gap="base"> <s-button variant="primary" commandFor="edit-modal" command="--show"> Edit customer </s-button> <s-modal id="edit-modal" heading="Edit customer information" size="large"> <s-stack gap="base"> <s-text-field label="Customer name" name="name" value="Sarah Johnson" ></s-text-field> <s-email-field label="Email address" name="email" value="sarah@example.com" ></s-email-field> <s-text-field label="Phone number" name="phone" value="+1 555-0123" ></s-text-field> <s-select label="Customer group" name="group"> <s-option value="retail">Retail</s-option> <s-option value="wholesale" selected>Wholesale</s-option> <s-option value="vip">VIP</s-option> </s-select> </s-stack> <s-button slot="primary-action" variant="primary" commandFor="edit-modal" command="--hide" > Save changes </s-button> <s-button slot="secondary-actions" variant="secondary" commandFor="edit-modal" command="--hide" > Cancel </s-button> </s-modal> </s-stack>Different modal sizes
Description
Demonstrates various modal sizes for different content requirements. Click each button to see different modal sizes.
jsx
<s-stack gap="base"> <s-stack direction="inline" gap="base"> <s-button commandFor="small-modal" command="--show"> Small modal </s-button> <s-button commandFor="large-modal" command="--show"> Large modal </s-button> </s-stack> {/* Small modal for quick confirmations */} <s-modal id="small-modal" heading="Confirm action" size="small-100"> <s-text>Are you sure you want to proceed?</s-text> <s-button slot="primary-action" variant="primary" commandFor="small-modal" command="--hide" > Confirm </s-button> <s-button slot="secondary-actions" variant="secondary" commandFor="small-modal" command="--hide" > Cancel </s-button> </s-modal> {/* Large modal for detailed content */} <s-modal id="large-modal" heading="Order details" size="large-100"> <s-stack gap="base"> <s-section> <s-heading>Order #1001</s-heading> <s-text>Placed on March 15, 2024</s-text> </s-section> <s-divider /> <s-section> <s-heading>Items</s-heading> <s-stack gap="small"> <s-text>Winter jacket - $89.99</s-text> <s-text>Wool scarf - $29.99</s-text> <s-text>Leather gloves - $45.99</s-text> </s-stack> </s-section> <s-divider /> <s-text type="strong">Total: $165.97</s-text> </s-stack> <s-button slot="primary-action" variant="primary" commandFor="large-modal" command="--hide" > Close </s-button> </s-modal> </s-stack>html
<s-stack gap="base"> <s-stack direction="inline" gap="base"> <s-button commandFor="small-modal" command="--show">Small modal</s-button> <s-button commandFor="large-modal" command="--show">Large modal</s-button> </s-stack> <!-- Small modal for quick confirmations --> <s-modal id="small-modal" heading="Confirm action" size="small-100"> <s-text>Are you sure you want to proceed?</s-text> <s-button slot="primary-action" variant="primary" commandFor="small-modal" command="--hide" > Confirm </s-button> <s-button slot="secondary-actions" variant="secondary" commandFor="small-modal" command="--hide" > Cancel </s-button> </s-modal> <!-- Large modal for detailed content --> <s-modal id="large-modal" heading="Order details" size="large-100"> <s-stack gap="base"> <s-section> <s-heading>Order #1001</s-heading> <s-text>Placed on March 15, 2024</s-text> </s-section> <s-divider></s-divider> <s-section> <s-heading>Items</s-heading> <s-stack gap="small"> <s-text>Winter jacket - $89.99</s-text> <s-text>Wool scarf - $29.99</s-text> <s-text>Leather gloves - $45.99</s-text> </s-stack> </s-section> <s-divider></s-divider> <s-text type="strong">Total: $165.97</s-text> </s-stack> <s-button slot="primary-action" variant="primary" commandFor="large-modal" command="--hide" > Close </s-button> </s-modal> </s-stack>Modal without padding
Description
Modal with no padding for full-width content. Click to view the modal.
jsx
<s-stack gap="base"> <s-button commandFor="image-modal" command="--show"> View product image </s-button> <s-modal id="image-modal" heading="Product image" padding="none"> <s-box background="subdued" padding="base"> <s-text>Image would display here with full width</s-text> </s-box> <s-button slot="secondary-actions" variant="secondary" commandFor="image-modal" command="--hide" > Close </s-button> </s-modal> </s-stack>html
<s-stack gap="base"> <s-button commandFor="image-modal" command="--show"> View product image </s-button> <s-modal id="image-modal" heading="Product image" padding="none"> <s-box background="subdued" padding="base"> <s-text>Image would display here with full width</s-text> </s-box> <s-button slot="secondary-actions" variant="secondary" commandFor="image-modal" command="--hide" > Close </s-button> </s-modal> </s-stack>