-
Notifications
You must be signed in to change notification settings - Fork 162
Snackbar Specification
Version | User | Date | Notes |
---|---|---|---|
0.1 | Zdravko Kolev | June 25, 2020 | Update spec based on new show message parameter |
0.2 | Desislava Dincheva | June 30, 2020 | Update the API specification |
igx-snackbar
is a native Angular component part of the JS Blocks family. It provides feedback about an operation by showing brief message at the bottom of the screen on mobile and lower left on larger devices. igx-Snackbar will appear above all other elements on screen and only one can be displayed at a time.
igx-snackbar
contains a single line of text directly related to the operation performed. It may contain a text action, but no icons.
Only one snackbar may be displayed at a time. Each snackbar may contain a single action, neither of which may be “Dismiss” or “Cancel”.
Provide means for the citizen developers to implement a simple common case snackbar, yet customizable list item with minimal efforts.
As a citizen developer, I want to be able to implement a material-styled snackbar component to notify users about occurred action and get input from them.
As an end user, I want to have a snackbar pop-up whenever I performed an action that is important or could be ‘undone’.
- Single line
- May contain text action
- Icons
- Be swiped off or automatically disappear
- On top of screen stack
- One snack bar could be present at a single time
- The material design guidelines
Snackbars automatically time out from the screen. For usability reasons, snackbars should not contain the only way to access a core use case. They should not be persistent or be stacked, as they are above other elements on screen.
There is only ever one snackbar displayed. When a second snackbar is triggered while the first is displayed, the first should start the contraction motion downwards before the second one animates upwards.
The igx-snackbar
is a material styled component
Note: Message
input will be deprecated.
You can show the Snackbar by using snackbar.show()
method, and change the message by passing a string value to the method e.g show("My custom message")
or by using content projection, which gives you the capabilities to place your message or any HTML element in the toast content giving you a more powerful and diverse way of toast content handling.
Snackbar content and message precedence. If all of the below is set simultaneously:
-
Content projection will be shown along with
show("custom message")
/input message property if there is the following configuration:
<igx-snackbar #toast>This is very important
</igx-snackbar>
..
this.snackbar.show("Another message");
Result:
Another message This is very important
<button (click)="snackbar.show()">Show snackbar</button>
<igx-snackbar #snackbar
message="This is a simple snackbar!">
</igx-snackbar>
You can be more descriptive and set message message="This is a simple snackbar!"
.
<button (click)="snackbar.show()">Show snackbar</button>
<igx-snackbar #snackbar
message="This is a snackbar with a button and action!"
actionName="Dismiss"
(onAction)="snackbar.hide()">
</igx-snackbar>
You can set the title of the button by setting actionName="Dismiss"
;
You can hide the Snackbar by using snackbar.hide()
method.
The Snackbar will be automatically hidden after 4000 milliseconds, this can be controller by the displayTime attribute, the automatic hiding can be also controller by using the displayTime attribute.
<button (click)="snackbar.show()">Show snackbar</button>
<igx-snackbar #snackbar
actionName="Dismiss"
(onAction)="snackbar.hide()">
<span>Custom content</span>
</igx-snackbar>
Snackbars appear above most elements on the screen, and they are equal in elevation to the floating action button. However, they are lower in elevation than dialogs, bottom sheets, and navigation drawers.
Upon entrance, snackbars animate upwards from the bottom edge of the screen. When they appear, they do not block input. They exit by being swiped off-screen or automatically disappear after a timeout or user interaction elsewhere (such as summoning a new surface or activity).
- Single-line snackbar height: 48dp
- Multi-line snackbar height: 80dp
- Text: Roboto Regular 14sp
- Action button: Roboto Medium 14sp, all-caps text
- Default background fill: #323232 100%
- Single-line snackbar height: 48dp tall
- Minimum width: 288dp
- Maximum width: 568dp
- 2dp rounded corner
- Text: Roboto Regular 14sp
- Action button: Roboto Medium 14sp, all-caps text
- Default background fill: #323232 100%
- Alignment: Centered or left-aligned 24dp from the left and bottom edges of the screen
The toast is a non-interactive component.
Properties
-
autoHide
- Sets/gets if the snackbar will be automatically hidden after thedisplayTime
is over. -
displayTime
- The duration of time span in ms in which the IgxSnackbar component will be visible after it is being shown. The default value is 4000. -
isVisible
- Represent the IgxSnackbar component visual state. The default value is false. -
message
- The message that will be shown message by the IgxSnackbar component. -
actionText
- Sets/gets theactionText
attribute, which will be displayed in the action button. - Methods
-
show()
- Shows the IgxToast component and hides it after some time span if autoHide is enabled. -
show("My custom message")
- Shows the IgxToast component with the passed message parameter - "My custom message". -
hide()
- Hides the IgxToast component. - Events
-
onAction
- An event that will be emitted when the action is executed. Provides reference to theIgxSnackbarComponent
as an argument. -
animationStarted
- An event that will be emitted when the snackbar animation starts. Provides reference to theAnimationEvent
interface as an argument. -
animationDone
- An event that will be emitted when the snackbar animation ends. Provides reference to theAnimationEvent
interface as an argument.
-
Roles
: - role="alert". https://www.w3.org/TR/wai-aria-practices/examples/alert/index.html