2.26.0
Alerts provide contextual information adjacent to items on the visible page. There are four types: error, warning, success, or informational.
That combination of options is invalid.
Name
|
Required
|
Description
|
---|---|---|
Message |
Yes |
Includes the core, most important alert content. |
Type |
Yes |
Affects the color and icon associated with the alert. Choose from error, warning, success or informational. |
Title |
No |
Briefly summarizes alert content. |
List |
No |
Helps structure content below a message element. |
Custom Action |
No |
Offers a follow-up action via secondary Button. |
Dismiss Action |
No |
Enables the user to remove the alert from view. |
Use for errors and malfunctions that must be resolved before moving forward, such as a summary of errors to correct in a Form.
<div class="mds-alert mds-alert--error" role="alert">
<div class="mds-alert__cell-icon">
<svg class="mds-icon mds-alert__icon" aria-hidden="true">
<use xlink:href="#alert">
</use>
</svg>
</div>
<div class="mds-alert__cell-body">
<aside class="mds-alert__content">
<strong class="mds-alert__title">Form Error</strong>
<p class="mds-alert__message">Correct all errors to continue.</p>
<ul class="mds-alert__list">
<li class="mds-alert__list-item">Last Name is required.</li>
<li class="mds-alert__list-item">E-mail is formatted incorrectly.</li>
</ul>
</aside>
</div>
</div>
<mds-alert title="Form Error" variation="error" list='["Last Name is required.", "E-mail is formatted incorrectly."]' dismissible="false">
Correct all errors to continue.
</mds-alert>
Use for a message requiring attention but not resolution in order to continue, such as noting data is not current or your password is about to expire.
<div class="mds-alert mds-alert--warning mds-alert--dismissible" role="alertdialog">
<div class="mds-alert__cell-icon">
<svg class="mds-icon mds-alert__icon" aria-hidden="true">
<use xlink:href="#alert">
</use>
</svg>
</div>
<div class="mds-alert__cell-body">
<aside class="mds-alert__content">
<strong class="mds-alert__title">You’re Saving More Than What the Government Allows</strong>
<p class="mds-alert__message">We advise you to adjust your contribution amounts and/or place any overflow into the <a href='#'>Additional Savings</a> field below. The next item on your advice list will show you how to invest it.</p>
</aside>
</div>
<button class="mds-button mds-button--small mds-button--icon-only mds-alert__dismiss-button" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--right" aria-hidden="true">
<use xlink:href="#remove--s">
</use>
</svg>
</button>
</div>
<mds-alert role="alertdialog" title="You’re Saving More Than What the Government Allows" variation="warning">
We advise you to adjust your contribution amounts and/or place any overflow into the <mds-link href="#">Additional Savings</mds-link> field below. The next item on your advice list will show you how to invest it.
</mds-alert>
Use to communicate that an action has been successfully completed, such as saving changes in a Form.
<div class="mds-alert mds-alert--success mds-alert--dismissible" role="alertdialog">
<div class="mds-alert__cell-icon">
<svg class="mds-icon mds-alert__icon" aria-hidden="true">
<use xlink:href="#check">
</use>
</svg>
</div>
<div class="mds-alert__cell-body">
<aside class="mds-alert__content">
<p class="mds-alert__message">Your address has been successfully updated.</p>
</aside>
</div>
<button class="mds-button mds-button--small mds-button--icon-only mds-alert__dismiss-button" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--right" aria-hidden="true">
<use xlink:href="#remove--s">
</use>
</svg>
</button>
</div>
<mds-alert role="alertdialog" variation="success">
Your address has been successfully updated.
</mds-alert>
Use to provide context around a situation, such as rules around creating a compliant password, or a link to feature documentation or onboarding tips.
<div class="mds-alert mds-alert--dismissible" role="alertdialog">
<div class="mds-alert__cell-icon">
<svg class="mds-icon mds-alert__icon" aria-hidden="true">
<use xlink:href="#info-circle">
</use>
</svg>
</div>
<div class="mds-alert__cell-body">
<aside class="mds-alert__content">
<strong class="mds-alert__title">What’s New</strong>
<p class="mds-alert__message">We’re building a new online experience with one goal in mind: to make the important investing work you do on our website easier and more intuitive.</p>
<ul class="mds-alert__list">
<li class="mds-alert__list-item">Today Page</li>
<li class="mds-alert__list-item">Streamlined Navigation</li>
<li class="mds-alert__list-item">Better Stock Investing</li>
<li class="mds-alert__list-item">Our Picks Center</li>
</ul>
<button class="mds-button mds-button--small mds-button--secondary" type="button">
Learn More
</button>
</aside>
</div>
<button class="mds-button mds-button--small mds-button--icon-only mds-alert__dismiss-button" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--right" aria-hidden="true">
<use xlink:href="#remove--s">
</use>
</svg>
</button>
</div>
<mds-alert role="alertdialog" title="What’s New" status="informational" list='["Today Page", "Streamlined Navigation", "Better Stock Investing", "Our Picks Center"]'>
We’re building a new online experience with one goal in mind: to make the important investing work you do on our website easier and more intuitive.
<mds-button slot="mds-alert-custom-action" size="small" variation="secondary"> Learn More </mds-button>
</mds-alert>
Sizing affects text size, icon size, and internal padding. The default size is medium, and you can use modifier classes or props to make the alert smaller or larger.
<div class="mds-alert mds-alert--small mds-alert--dismissible" role="alertdialog">
<div class="mds-alert__cell-icon">
<svg class="mds-icon mds-alert__icon" aria-hidden="true">
<use xlink:href="#info-circle--s">
</use>
</svg>
</div>
<div class="mds-alert__cell-body">
<aside class="mds-alert__content">
<strong class="mds-alert__title">Alert Title</strong>
<p class="mds-alert__message">Alert message, including <a href='#'>a link</a>.</p>
<ul class="mds-alert__list">
<li class="mds-alert__list-item">List Item 1</li>
<li class="mds-alert__list-item">List Item 2</li>
</ul>
<button class="mds-button mds-button--small mds-button--secondary" type="button">
Take Action
</button>
</aside>
</div>
<button class="mds-button mds-button--small mds-button--icon-only mds-alert__dismiss-button" type="button">
<svg class="mds-icon mds-button__icon mds-button__icon--right" aria-hidden="true">
<use xlink:href="#remove--s">
</use>
</svg>
</button>
</div>
<mds-alert size="small" role="alertdialog" title="Alert Title" list='["List Item 1", "List Item 2"]'>
Alert message including <mds-link href="#">a link</mds-link>.
<mds-button slot="mds-alert-custom-action" size="small" variation="secondary"> Take Action </mds-button>
</mds-alert>
remove--s
.For additional editorial guidance, refer to Buttons and Errors documentation.
Class
|
Applies to
|
Outcome
|
---|---|---|
|
|
Reduces text size, icon size, and internal padding. |
|
|
Adds padding to the right side of the body of the alert to accommodate the close icon. |
|
|
Dismisses the alert by animating fade-out and slide-up effects. |
|
|
Applies the green background color and the white icon color to the left side of the component. |
|
|
Applies the yellow background color and the black icon color to the left side of the component. |
|
|
Applies the red background color and the white icon color to the left side of the component. |
|
|
Applies the tinted background color to the body of the component. |
When setting props as attributes on a custom HTML element, use kebab-case
instead of camelCase
.
Prop
|
Type
|
Validation
|
Default
|
Description
|
---|---|---|---|---|
|
String |
— |
— |
A space-separated list of class names that will be appended to the default |
|
String |
One of: |
— |
Sets the aria-live attribute. |
|
Boolean |
— |
|
If true, adds an icon-only dismiss button that allows the alert to be dismissed. |
|
String |
— |
|
Sets the |
|
Array |
— |
— |
Sets list content of the alert. |
|
Boolean |
Only valid when |
|
If true, removes the alert from the DOM after the dismiss animation completes. If false, alert is simply hidden when dismissed, not removed. |
|
String |
— |
— |
|
|
String |
One of: |
|
Alters the size of the alert. |
|
String |
Required |
— |
The text that appears in the alert. Can also be passed via the default slot. |
|
Boolean |
— |
|
If true, adds the tinted background color to the body of the alert. |
|
String |
— |
— |
Sets the title of the alert. |
|
String |
One of: |
|
Sets the variation of the alert. |
Pass text in between the <mds-alert></mds-alert>
tags to set the alert’s text. This can be overridden with the text
prop.
Slot Name
|
Description
|
---|---|
|
Markup for elements that provide functionality related to the alert, like Buttons. |
Method Name
|
Description
|
---|---|
|
A method which is also invoked internally when the icon-only dismiss button is clicked. Useful for programmatically calling |
Event Name
|
Description
|
---|---|
|
If |
|
If |
Setting text
. status
, and size
via props:
<mds-alert text="This is a sample alert message." status="error" size="small"></mds-alert>
Setting title
and list
via props. Using the default slot for text
content:
<mds-alert title="A list of alerts" list='["List item 1", "List item 2"]'>
This is a sample alert message.
</mds-alert>
Setting dismissible
via props. Using named slots for mds-alert-custom-action
. Using the default slot for text
content:
<mds-alert dismissible=false>
This is a sample alert message.
<mds-button slot="mds-alert-custom-action" size="small" variation="secondary"> Take Action </mds-button>
</mds-alert>
role="alert"
attribute on the mds-alert
element.role="alertdialog"
attribute on the mds-alert
element if alert provides interactive controls, such as a dismiss or custom action.aria-invalid="true"
attribute to an input that triggers an error alert.tab-index
to -1
and disable any contained interactive elements.aria-live="assertive"
attribute to interrupt the user’s workflow when an alert contains critical information, like an error.aria-live="polite"
attribute to wait until after the current content is read to announce an alert that contains non-critical information, like a warning, success, or informational..mds-alert_title
element a unique id
and set it as the .mds-alert
element’s aria-labelledby
attribute, for example:<div class="mds-alert" aria-labelledby="warning1Title">
...
<div class="mds-alert__title" id="warning1Title">
...
.mds-alert_message
element a unique id
and set it as the .mds-alert
element’s aria-describededby
attribute, for example:<div class="mds-alert" aria-describedby=“warning1Desc”>
...
<div class="mds-alert__message" id="warning1Desc">
...
When constructing an alert’s message, consider how it will be read by a screen reader:
Alerts should be used sparingly and only in instances that warrant removing the user from their current task. Too many alerts can be disorienting to users with cognitive issues.