Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions js/toasts.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@
_createToast() {
let toast = document.createElement('div');
toast.classList.add('toast');
toast.setAttribute('role', 'alert');
toast.setAttribute('aria-live', 'assertive');
toast.setAttribute('aria-atomic', true);

// Add custom classes onto toast
if (!!this.options.classes.length) {
Expand Down
12 changes: 6 additions & 6 deletions pug/page-contents/toasts_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

<div id="introduction" class="section scrollspy">
<p>Materialize provides an easy way for you to send unobtrusive alerts to your users through toasts. These toasts are also placed and sized responsively, try it out by clicking the button below on different device sizes.</p>
<a class="waves-effect waves-light btn" onclick="M.toast({text: 'I am a toast'})">Toast!</a>
<button type="button" class="waves-effect waves-light btn" onclick="M.toast({text: 'I am a toast'})">Toast!</button>
<p>To do this, call the M.toast() function programmatically in JavaScript.</p>
<pre><code class="language-javascript">
M.toast({text: 'I am a toast!'})
</code></pre>
<p>One way to add this into your application is to add this as an onclick event to a button.</p>
<pre><code class="language-markup">
&lt;a onclick="M.toast({text: 'I am a toast'})" class="btn">Toast!&lt;/a>
&lt;button type="button" onclick="M.toast({text: 'I am a toast'})" class="btn">Toast!&lt;/button>
</code></pre>
</div>

Expand Down Expand Up @@ -149,7 +149,7 @@ <h3 class="header">Custom HTML</h3>
<p>
Only use a properly sanitized or otherwise trusted HTML string.
</p>
<a class="waves-effect waves-light btn" onclick="displayCustomHTMLToast()">Toast with Action</a>
<button type="button" class="waves-effect waves-light btn" onclick="displayCustomHTMLToast()">Toast with Action</button>
<pre><code class="language-javascript">
var toastHTML = '&lt;span>I am toast content&lt;/span>&lt;button class="btn-flat toast-action">Undo&lt;/button>';
M.toast({unsafeHTML: toastHTML});
Expand All @@ -160,9 +160,9 @@ <h3 class="header">Custom HTML</h3>
<div id="callback" class="scrollspy section">
<h3 class="header">Callback</h3>
<p>You can have the toast callback a function when it has been dismissed.</p>
<a class="btn" onclick="M.toast({text: 'I am a toast', completeCallback: function(){alert('Your toast was dismissed')}})">Toast!</a>
<button type="button" class="btn" onclick="M.toast({text: 'I am a toast', completeCallback: function(){alert('Your toast was dismissed')}})">Toast!</button>
<pre><code class="language-markup">
&lt;a class="btn" onclick="M.toast({text: 'I am a toast', completeCallback: function(){alert('Your toast was dismissed')}})">Toast!&lt;/a>
&lt;button type="button" class="btn" onclick="M.toast({text: 'I am a toast', completeCallback: function(){alert('Your toast was dismissed')}})">Toast!&lt;/button>
</code></pre>
</div>

Expand All @@ -171,7 +171,7 @@ <h3 class="header">Callback</h3>
<h3 class="header">Styling Toasts</h3>
<p>We've added the ability to customize your toasts easily. You can pass in classes as an optional parameter into the toast function. We've added a rounded class for you, but you can create your own CSS classes and apply them to toasts. Checkout out our full example below.</p>

<a class="waves-effect waves-light btn" onclick="M.toast({text: 'I am a toast!', classes: 'rounded'})">Round Toast!</a>
<button type="button" class="waves-effect waves-light btn" onclick="M.toast({text: 'I am a toast!', classes: 'rounded'})">Round Toast!</button>

<pre><code class="language-javascript">
// 'rounded' is the class I'm applying to the toast
Expand Down
16 changes: 8 additions & 8 deletions test/html/toast.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,30 @@
<body>

<div class="container">
<a onclick="toast1()" class="btn">Toast with text!</a>
<a onclick="toast2()" class="btn">Toast with html!</a>
<a onclick="toast3()" class="btn">Toast with unsafeHTML!</a>
<a onclick="toast4()" class="btn">Toast with unsafeHTML and text!</a>
<button type="button" onclick="toast1()" class="btn">Toast with text!</button>
<button type="button" onclick="toast2()" class="btn">Toast with html!</button>
<button type="button" onclick="toast3()" class="btn">Toast with unsafeHTML!</button>
<button type="button" onclick="toast4()" class="btn">Toast with unsafeHTML and text!</button>
</div>

<!-- Scripts -->
<script src="../../bin/materialize.js"></script>

<script type="text/javascript">
function toast1() {
text = '<span>I am toast content</span><button class="btn-flat toast-action">Undo</button>';
text = '<span>I am toast content</span><button type="button" class="btn-flat toast-action">Undo</button>';
M.toast({text: text});
}
function toast2() {
text = '<span>I am toast content</span><button class="btn-flat toast-action">Undo</button>';
text = '<span>I am toast content</span><button type="button" class="btn-flat toast-action">Undo</button>';
M.toast({html: text});
}
function toast3() {
text = '<span>I am toast content</span><button class="btn-flat toast-action">Undo</button>';
text = '<span>I am toast content</span><button type="button" class="btn-flat toast-action">Undo</button>';
M.toast({unsafeHTML: text});
}
function toast4() {
text = '<span>I am toast content</span><button class="btn-flat toast-action">Undo</button>';
text = '<span>I am toast content</span><button type="button" class="btn-flat toast-action">Undo</button>';
M.toast({unsafeHTML: text, text: text});
}
</script>
Expand Down
3 changes: 3 additions & 0 deletions tests/spec/toast/toastSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ describe( 'Toasts:', function() {
setTimeout(function() {
toast = document.querySelectorAll('.toast');
expect(toast.length).toBe(1);
expect(toast[0].getAttribute("role")).toBe("alert");
expect(toast[0].getAttribute("aria-live")).toBe("assertive");
expect(toast[0].getAttribute("aria-atomic")).toBe("true");
expect(toast[0]).toBeVisible();
expect(toast[0].innerText).toBe('Test toast');
setTimeout(function() {
Expand Down