-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create an attribute and property for toast closebutton and attach clo…
…se functionality This change sets the groundwork for the toast closebutton, by adding an attribute to set the closebutton content, creating a closeButton property to reflect that attribute, and adding an event listener to close the toast when the closebutton is pressed. This change implements the close button API described in (https://github.com/jackbsteinberg/std-toast/blob/eec7728f7082a897d777181ac07b0448062ffca5/README.md), and is the subject of debate on issue #48 on the explainer here jackbsteinberg/std-toast#48. Future CLs will add the closeButton option for showToast (https://github.com/jackbsteinberg/std-toast/tree/master#showtoastmessage-options) Link: https://chromium-review.googlesource.com/c/chromium/src/+/1706453 Bug:972945 Change-Id: I5d6c3055791a9f93ef414e575e128c61e2a944ed
- Loading branch information
1 parent
ad422d2
commit f386280
Showing
2 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Toast: closebutton tests</title> | ||
|
||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<main></main> | ||
|
||
<script type="module"> | ||
import { testToastElement } from './resources/helpers.js'; | ||
|
||
testToastElement((toast) => { | ||
toast.setAttribute('closebutton', ''); | ||
|
||
assert_true(toast.closeButton); | ||
}, 'the closeButton property returns true with an empty attribute'); | ||
|
||
testToastElement((toast) => { | ||
toast.setAttribute('closebutton', 'dismiss'); | ||
|
||
assert_equals(toast.closeButton, 'dismiss'); | ||
}, 'the closeButton property returns the set attribute value'); | ||
|
||
testToastElement((toast) => { | ||
assert_false(toast.closeButton); | ||
}, 'the closeButton property returns false with no attribute'); | ||
|
||
testToastElement((toast) => { | ||
toast.setAttribute('closebutton', ''); | ||
assert_true(toast.closeButton); | ||
|
||
toast.setAttribute('closebutton', 'dismiss'); | ||
assert_equals(toast.closeButton, 'dismiss'); | ||
|
||
toast.removeAttribute('closebutton'); | ||
assert_false(toast.closeButton); | ||
}, 'the closeButton property changes when the attribute changes'); | ||
|
||
testToastElement((toast) => { | ||
toast.closeButton = 'dismiss'; | ||
|
||
assert_equals(toast.getAttribute('closebutton'), 'dismiss'); | ||
}, 'setting the closeButton property to any string changes the attribute to that string'); | ||
|
||
testToastElement((toast) => { | ||
toast.closeButton = ''; | ||
|
||
assert_equals(toast.getAttribute('closebutton'), ''); | ||
}, 'setting the closeButton property to empty string changes the attribute to empty string'); | ||
|
||
testToastElement((toast) => { | ||
toast.closeButton = true; | ||
|
||
assert_equals(toast.getAttribute('closebutton'), ''); | ||
}, 'setting the closeButton property to true changes the attribute to empty string'); | ||
|
||
testToastElement((toast) => { | ||
toast.closeButton = false; | ||
|
||
assert_false(toast.hasAttribute('closebutton')); | ||
}, 'setting the closeButton property to false removes the attribute'); | ||
|
||
testToastElement((toast) => { | ||
toast.closeButton = undefined; | ||
|
||
assert_equals(toast.getAttribute('closebutton'), 'undefined'); | ||
}, 'setting the closeButton property to undefined stringifies and sets to that'); | ||
|
||
testToastElement((toast) => { | ||
toast.closeButton = null; | ||
|
||
assert_equals(toast.getAttribute('closebutton'), 'null'); | ||
}, 'setting the closeButton property to null stringifies and sets to that'); | ||
|
||
testToastElement((toast) => { | ||
toast.closeButton = {}; | ||
|
||
assert_equals(toast.getAttribute('closebutton'), '[object Object]'); | ||
}, 'setting the closeButton property to {} stringifies and sets to [object Object]'); | ||
</script> |