Display info, success, warning and error messages.
Usage
To apply this component, add the gls-alert
attribute to a block element.
<div gls-alert role="alert"></div>
-
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
<div gls-alert role="alert">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
Guidelines
When to use
- To notify users about system status including error, warnings, and updates.
- To notify users they’ve successfully completed a task
- Use along with inline validation alerts to summarize multiple errors on longer forms
When to use something else
- When it’s necessary to interrupt the user’s work flow.
- When user input/action is required to continue working
- If action taken by the user will result in losing/destroying their work, use a modal dialog that allows the user to confirm the destructive action.
Accessibility
- Alerts should use the
role="alert"
attribute - Alerts that have a dismiss or close button should use the
role="alertdialog"
attribute - Use the
aria-labelledby
attribute to link the alert title with the alert element - Dynamically rendered alerts are automatically announced by most screen readers, but it’s important to note that screen readers will not inform users of alerts that are present before a page has finished loading
Microcopy notes
- Alert title should be clear and concise. “Success!” rather than “Application was submitted successfully!"
- Alert message should be descriptive and should clearly articulate the problem the user has encountered or the information you are trying to convey to the user. “The user ID and password you entered do not match” is more clear than “Unauthorized”.
- Where appropriate, alert title should be a link to the position on the page where the invalid element can be found.
- Alert message should offer next steps where appropriate.
Close button
To create a close button and enable its functionality, add the .gls-alert-close
class to a <button>
or <a>
element inside the alert box. To apply a close icon, add the gls-close
attribute from the Close component.
<div gls-alert role="alertdialog">
<a class="gls-alert-close" gls-close></a>
</div>
<div gls-alert role="alertdialog"> <a class="gls-alert-close" gls-close></a> <h3>Notice</h3> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p> </div>
Style modifiers
There are several style modifiers available. Just add one of the following classes to apply a different look.
Class | Description |
---|---|
.gls-alert-primary |
Give the message a prominent styling. |
.gls-alert-success |
Indicates success or a positive message. |
.gls-alert-warning |
Indicates a message containing a warning. |
.gls-alert-danger |
Indicates an important or error message. |
.gls-alert-info |
Indicates an informational message. |
<div class="gls-alert-primary" gls-alert role="alertdialog"> <a class="gls-alert-close" gls-close></a> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.</p> </div> <div class="gls-alert-info" gls-alert role="alertdialog"> <a class="gls-alert-close" gls-close></a> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.</p> </div> <div class="gls-alert-success" gls-alert role="alertdialog"> <a class="gls-alert-close" gls-close></a> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.</p> </div> <div class="gls-alert-warning" gls-alert role="alertdialog"> <a class="gls-alert-close" gls-close></a> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.</p> </div> <div class="gls-alert-danger" gls-alert role="alertdialog"> <a class="gls-alert-close" gls-close></a> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt.</p> </div>
Component options
Any of these options can be applied to the component attribute. Separate multiple options with a semicolon. Learn more
Option | Value | Default | Description |
---|---|---|---|
animation |
Boolean, String | true |
Fade out or use the Animation component. |
duration |
Number | 150 |
Animation duration in milliseconds. |
sel-close |
CSS selector | .gls-alert-close |
The close trigger element. |
animation
is the Primary option and its key may be omitted, if it’s the only option in the attribute value.
<span gls-toggle=".my-class"></span>
JavaScript
Learn more about JavaScript components.
Initialization
Gloss.alert(element, options);
Events
The following events will be triggered on elements with this component attached:
Name | Description |
---|---|
beforehide |
Fires before an item is hidden. Can prevent hiding by calling preventDefault() on the event. |
hide |
Fires after an item is hidden. |
Methods
The following methods are available for the component:
Close
Gloss.alert(element).close();
Closes and removes the Alert.