Commit 6a6b173b authored by Jack Steinberg's avatar Jack Steinberg Committed by Commit Bot

Add type option to showToast helper

Bug: 972945
Change-Id: I1fb8f40b491fa86aa1e11fe7764446da110dcc32
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1713387
Commit-Queue: Jack Steinberg <jacksteinberg@chromium.org>
Reviewed-by: default avatarFergal Daly <fergal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#680143}
parent b2e5772f
......@@ -211,7 +211,13 @@ delete StdToastElement.prototype.connectedCallback;
export function showToast(message, options = {}) {
const toast = new StdToastElement(message);
const {action, closeButton, ...showOptions} = options;
const {
action,
closeButton,
type,
...showOptions
} = options;
if (isElement(action)) {
toast.action = action;
} else if (action !== undefined) {
......@@ -229,6 +235,10 @@ export function showToast(message, options = {}) {
toast.closeButton = closeButton;
}
if (type !== undefined) {
toast.type = type;
}
document.body.append(toast);
toast.show(showOptions);
......
......@@ -101,4 +101,23 @@ async_test(t => {
toast.remove();
});
}, 'showToast closes after user specified 50ms');
// type
test(() => {
const toast = showToast('Message', {type: 'warning'});
assert_equals(toast.type, 'warning');
assert_equals(toast.getAttribute('type'), 'warning');
}, 'passing a valid type option to showToast sets the type property and attribute');
test(() => {
const toast = showToast('Message', {type: 'test'});
assert_equals(toast.type, '');
assert_equals(toast.getAttribute('type'), 'test');
}, 'passing an invalid type option to showToast sets the type attribute, but not the property');
test(() => {
const toast = showToast('Message');
assert_equals(toast.type, '');
assert_false(toast.hasAttribute('type'));
}, 'passing nothing as the type option to showToast does not set the type attribute or property');
</script>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment