@aurodesignsystem-dev/auro-toast 0.0.0-pr121.2 → 0.0.0-pr121.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/demo/api.js +4 -0
- package/demo/api.md +243 -37
- package/demo/api.min.js +91 -6
- package/demo/basic.min.js +294 -38
- package/demo/index.md +10 -2
- package/dist/{auro-toaster-Bll35Bgq.js → auro-toaster-C16e0fNp.js} +39 -37
- package/dist/index.d.ts +14 -0
- package/dist/index.js +1 -1
- package/dist/registered.js +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -89,8 +89,12 @@ In cases where the project is not able to process JS assets, there are pre-proce
|
|
|
89
89
|
<auro-button id="basicToastBtn">
|
|
90
90
|
Show default notification
|
|
91
91
|
</auro-button>
|
|
92
|
+
<!--
|
|
93
|
+
NOTE: The manually added style is NOT necessary for use,
|
|
94
|
+
Demo purposes ONLY!
|
|
95
|
+
-->
|
|
92
96
|
<auro-toast style="display: block; margin: 0.5rem 0;" id="basicToast">
|
|
93
|
-
Default notification with no error type
|
|
97
|
+
Default notification with no error type.
|
|
94
98
|
</auro-toast>
|
|
95
99
|
```
|
|
96
100
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
@@ -126,7 +130,7 @@ This will create a new custom element `<custom-toast>` that behaves exactly like
|
|
|
126
130
|
Show default notification
|
|
127
131
|
</auro-button>
|
|
128
132
|
<custom-toast style="display: block; margin: 0.5rem 0;" id="customToast">
|
|
129
|
-
Default notification with no error type
|
|
133
|
+
Default notification with no error type.
|
|
130
134
|
</custom-toast>
|
|
131
135
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
132
136
|
</div>
|
|
@@ -140,7 +144,7 @@ This will create a new custom element `<custom-toast>` that behaves exactly like
|
|
|
140
144
|
Show default notification
|
|
141
145
|
</auro-button>
|
|
142
146
|
<custom-toast style="display: block; margin: 0.5rem 0;" id="customToast">
|
|
143
|
-
Default notification with no error type
|
|
147
|
+
Default notification with no error type.
|
|
144
148
|
</custom-toast>
|
|
145
149
|
```
|
|
146
150
|
<!-- AURO-GENERATED-CONTENT:END -->
|
package/demo/api.js
CHANGED
|
@@ -7,6 +7,8 @@ import { initCustomToastExample } from "../apiExamples/custom-toast";
|
|
|
7
7
|
import { initVisibleExample } from "../apiExamples/visible";
|
|
8
8
|
import { initMultipleToastsExample } from "../apiExamples/multiple-toasts";
|
|
9
9
|
import { initDynamicToastsExample } from "../apiExamples/dynamic-toasts";
|
|
10
|
+
import { initStandaloneToastExample } from "../apiExamples/standalone-toast";
|
|
11
|
+
import { initTriggerExample } from "../apiExamples/trigger";
|
|
10
12
|
|
|
11
13
|
import "../src/registered";
|
|
12
14
|
/* eslint-disable jsdoc/require-jsdoc, no-magic-numbers, no-param-reassign */
|
|
@@ -26,6 +28,8 @@ export function initExamples(initCount) {
|
|
|
26
28
|
initVisibleExample();
|
|
27
29
|
initMultipleToastsExample();
|
|
28
30
|
initDynamicToastsExample();
|
|
31
|
+
initStandaloneToastExample();
|
|
32
|
+
initTriggerExample();
|
|
29
33
|
} catch (_err) {
|
|
30
34
|
if (initCount <= 20) {
|
|
31
35
|
// setTimeout handles issue where content is sometimes loaded after the functions get called
|
package/demo/api.md
CHANGED
|
@@ -7,13 +7,15 @@ The `auro-toast` element provides users a way to display short, temporary messag
|
|
|
7
7
|
|
|
8
8
|
### Properties & Attributes
|
|
9
9
|
|
|
10
|
-
| Properties | Attributes | Modifiers | Type | Default | Description
|
|
11
|
-
| --------------- | --------------- | --------- | -------------------------------- | ------- |
|
|
12
|
-
| disableAutoHide | disableAutoHide | | boolean | | Prevents the toast from auto-hiding on the default time.
|
|
13
|
-
| noIcon | noIcon | | boolean | | Removes icon from the toast UI.
|
|
14
|
-
| timeTilHide | timeTilHide | | number | | Sets the time in milliseconds until the toast hides.
|
|
15
|
-
|
|
|
16
|
-
|
|
|
10
|
+
| Properties | Attributes | Modifiers | Type | Default | Description |
|
|
11
|
+
| --------------- | --------------- | --------- | -------------------------------- | ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
12
|
+
| disableAutoHide | disableAutoHide | | boolean | | Prevents the toast from auto-hiding on the default time. |
|
|
13
|
+
| noIcon | noIcon | | boolean | | Removes icon from the toast UI. |
|
|
14
|
+
| timeTilHide | timeTilHide | | number | | Sets the time in milliseconds until the toast hides. |
|
|
15
|
+
| trigger | trigger | | string | | The id of the element that triggered the toast.<br>When the toast is manually closed, focus will return to this element.<br>Takes precedence over the triggerElement property if both are set. |
|
|
16
|
+
| triggerElement | | | HTMLElement | | A direct reference to the element that triggered the toast.<br>When the toast is manually closed, focus will return to this element.<br>Use the trigger attribute instead if you prefer a declarative approach. |
|
|
17
|
+
| variant | variant | | `error` \| `success` \| `custom` | | Component will render visually based on which variant value is set. |
|
|
18
|
+
| visible | visible | | boolean | | Sets state of toast to visible |
|
|
17
19
|
|
|
18
20
|
### Methods
|
|
19
21
|
|
|
@@ -43,8 +45,12 @@ The `auro-toast` element provides users a way to display short, temporary messag
|
|
|
43
45
|
<auro-button id="basicToastBtn">
|
|
44
46
|
Show default notification
|
|
45
47
|
</auro-button>
|
|
48
|
+
<!--
|
|
49
|
+
NOTE: The manually added style is NOT necessary for use,
|
|
50
|
+
Demo purposes ONLY!
|
|
51
|
+
-->
|
|
46
52
|
<auro-toast style="display: block; margin: 0.5rem 0;" id="basicToast">
|
|
47
|
-
Default notification with no error type
|
|
53
|
+
Default notification with no error type.
|
|
48
54
|
</auro-toast>
|
|
49
55
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
50
56
|
</div>
|
|
@@ -57,8 +63,12 @@ The `auro-toast` element provides users a way to display short, temporary messag
|
|
|
57
63
|
<auro-button id="basicToastBtn">
|
|
58
64
|
Show default notification
|
|
59
65
|
</auro-button>
|
|
66
|
+
<!--
|
|
67
|
+
NOTE: The manually added style is NOT necessary for use,
|
|
68
|
+
Demo purposes ONLY!
|
|
69
|
+
-->
|
|
60
70
|
<auro-toast style="display: block; margin: 0.5rem 0;" id="basicToast">
|
|
61
|
-
Default notification with no error type
|
|
71
|
+
Default notification with no error type.
|
|
62
72
|
</auro-toast>
|
|
63
73
|
```
|
|
64
74
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
@@ -77,7 +87,7 @@ Use the `disableAutoHide` attribute to prevent the toast from automatically dism
|
|
|
77
87
|
Show default notification
|
|
78
88
|
</auro-button>
|
|
79
89
|
<auro-toast style="display: block; margin: 0.5rem 0;" id="disableHideToast">
|
|
80
|
-
Default notification with no error type
|
|
90
|
+
Default notification with no error type.
|
|
81
91
|
</auro-toast>
|
|
82
92
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
83
93
|
</div>
|
|
@@ -91,7 +101,7 @@ Use the `disableAutoHide` attribute to prevent the toast from automatically dism
|
|
|
91
101
|
Show default notification
|
|
92
102
|
</auro-button>
|
|
93
103
|
<auro-toast style="display: block; margin: 0.5rem 0;" id="disableHideToast">
|
|
94
|
-
Default notification with no error type
|
|
104
|
+
Default notification with no error type.
|
|
95
105
|
</auro-toast>
|
|
96
106
|
```
|
|
97
107
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
@@ -105,7 +115,7 @@ Using the `noIcon` attribute will set no icon to be visible in the notification.
|
|
|
105
115
|
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../apiExamples/no-icon.html) -->
|
|
106
116
|
<!-- The below content is automatically added from ./../apiExamples/no-icon.html -->
|
|
107
117
|
<auro-button id="noIconBtn"> Show toast with no icon </auro-button>
|
|
108
|
-
<auro-toast id="noIcon" noIcon style="display: block; margin: 0.5rem 0;"> Default toast </auro-toast>
|
|
118
|
+
<auro-toast id="noIcon" noIcon style="display: block; margin: 0.5rem 0;"> Default toast. </auro-toast>
|
|
109
119
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
110
120
|
</div>
|
|
111
121
|
<auro-accordion alignRight>
|
|
@@ -115,7 +125,7 @@ Using the `noIcon` attribute will set no icon to be visible in the notification.
|
|
|
115
125
|
|
|
116
126
|
```html
|
|
117
127
|
<auro-button id="noIconBtn"> Show toast with no icon </auro-button>
|
|
118
|
-
<auro-toast id="noIcon" noIcon style="display: block; margin: 0.5rem 0;"> Default toast </auro-toast>
|
|
128
|
+
<auro-toast id="noIcon" noIcon style="display: block; margin: 0.5rem 0;"> Default toast. </auro-toast>
|
|
119
129
|
```
|
|
120
130
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
121
131
|
</auro-accordion>
|
|
@@ -131,7 +141,7 @@ Using the `timeTilHide` attribute will set a timer in milliseconds for how long
|
|
|
131
141
|
Show default notification
|
|
132
142
|
</auro-button>
|
|
133
143
|
<auro-toast timeTilHide="1000" style="display: block; margin: 0.5rem 0;" id="timeTilHideToast">
|
|
134
|
-
Default notification with no error type
|
|
144
|
+
Default notification with no error type.
|
|
135
145
|
</auro-toast>
|
|
136
146
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
137
147
|
</div>
|
|
@@ -145,7 +155,7 @@ Using the `timeTilHide` attribute will set a timer in milliseconds for how long
|
|
|
145
155
|
Show default notification
|
|
146
156
|
</auro-button>
|
|
147
157
|
<auro-toast timeTilHide="1000" style="display: block; margin: 0.5rem 0;" id="timeTilHideToast">
|
|
148
|
-
Default notification with no error type
|
|
158
|
+
Default notification with no error type.
|
|
149
159
|
</auro-toast>
|
|
150
160
|
```
|
|
151
161
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
@@ -164,19 +174,19 @@ What the component will render visually based on which variant value is set; cur
|
|
|
164
174
|
Show default toast
|
|
165
175
|
</auro-button>
|
|
166
176
|
<auro-toast id="defaultVariant" style="display: block; margin: 0.5rem 0;">
|
|
167
|
-
Default toast
|
|
177
|
+
Default toast.
|
|
168
178
|
</auro-toast>
|
|
169
179
|
<auro-button id="errorVariantBtn">
|
|
170
180
|
Show error toast
|
|
171
181
|
</auro-button>
|
|
172
182
|
<auro-toast id="errorVariant" variant="error" style="display: block; margin: 0.5rem 0;">
|
|
173
|
-
Unable to add lap infant. Please try again
|
|
183
|
+
Unable to add lap infant. Please try again.
|
|
174
184
|
</auro-toast>
|
|
175
185
|
<auro-button id="successVariantBtn">
|
|
176
186
|
Show success toast
|
|
177
187
|
</auro-button>
|
|
178
188
|
<auro-toast id="successVariant" variant="success" style="display: block; margin: 0.5rem 0;">
|
|
179
|
-
Successfully added lap infant
|
|
189
|
+
Successfully added lap infant.
|
|
180
190
|
</auro-toast>
|
|
181
191
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
182
192
|
</div>
|
|
@@ -190,19 +200,19 @@ What the component will render visually based on which variant value is set; cur
|
|
|
190
200
|
Show default toast
|
|
191
201
|
</auro-button>
|
|
192
202
|
<auro-toast id="defaultVariant" style="display: block; margin: 0.5rem 0;">
|
|
193
|
-
Default toast
|
|
203
|
+
Default toast.
|
|
194
204
|
</auro-toast>
|
|
195
205
|
<auro-button id="errorVariantBtn">
|
|
196
206
|
Show error toast
|
|
197
207
|
</auro-button>
|
|
198
208
|
<auro-toast id="errorVariant" variant="error" style="display: block; margin: 0.5rem 0;">
|
|
199
|
-
Unable to add lap infant. Please try again
|
|
209
|
+
Unable to add lap infant. Please try again.
|
|
200
210
|
</auro-toast>
|
|
201
211
|
<auro-button id="successVariantBtn">
|
|
202
212
|
Show success toast
|
|
203
213
|
</auro-button>
|
|
204
214
|
<auro-toast id="successVariant" variant="success" style="display: block; margin: 0.5rem 0;">
|
|
205
|
-
Successfully added lap infant
|
|
215
|
+
Successfully added lap infant.
|
|
206
216
|
</auro-toast>
|
|
207
217
|
```
|
|
208
218
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
@@ -229,7 +239,7 @@ The toast notification can be customized in several ways.
|
|
|
229
239
|
variant="custom"
|
|
230
240
|
visible
|
|
231
241
|
disableAutoHide
|
|
232
|
-
style="--ds-auro-toast-container-color: var(--ds-color-background-info-default); --ds-auro-toast-text-color: var(--ds-color-text-primary-default);">
|
|
242
|
+
style="--ds-auro-toast-container-color: var(--ds-color-background-info-default); --ds-auro-toast-text-color: var(--ds-color-text-primary-default); display: block; margin: 0.5rem 0;">
|
|
233
243
|
Did you know you can create a price alert for this route?
|
|
234
244
|
<br />
|
|
235
245
|
<auro-button variant="tertiary">Create Alert</auro-button>
|
|
@@ -252,7 +262,7 @@ The toast notification can be customized in several ways.
|
|
|
252
262
|
variant="custom"
|
|
253
263
|
visible
|
|
254
264
|
disableAutoHide
|
|
255
|
-
style="--ds-auro-toast-container-color: var(--ds-color-background-info-default); --ds-auro-toast-text-color: var(--ds-color-text-primary-default);">
|
|
265
|
+
style="--ds-auro-toast-container-color: var(--ds-color-background-info-default); --ds-auro-toast-text-color: var(--ds-color-text-primary-default); display: block; margin: 0.5rem 0;">
|
|
256
266
|
Did you know you can create a price alert for this route?
|
|
257
267
|
<br />
|
|
258
268
|
<auro-button variant="tertiary">Create Alert</auro-button>
|
|
@@ -273,7 +283,7 @@ State of the push notification which determines if it is `visible`.
|
|
|
273
283
|
Set visible to true
|
|
274
284
|
</auro-button>
|
|
275
285
|
<auro-toast id="visibleToast" style="display: block; margin: 0.5rem 0;">
|
|
276
|
-
Default toast
|
|
286
|
+
Default toast.
|
|
277
287
|
</auro-toast>
|
|
278
288
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
279
289
|
</div>
|
|
@@ -287,12 +297,136 @@ State of the push notification which determines if it is `visible`.
|
|
|
287
297
|
Set visible to true
|
|
288
298
|
</auro-button>
|
|
289
299
|
<auro-toast id="visibleToast" style="display: block; margin: 0.5rem 0;">
|
|
290
|
-
Default toast
|
|
300
|
+
Default toast.
|
|
291
301
|
</auro-toast>
|
|
292
302
|
```
|
|
293
303
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
294
304
|
</auro-accordion>
|
|
295
305
|
|
|
306
|
+
### Focus Management — trigger and triggerElement
|
|
307
|
+
|
|
308
|
+
When a toast is manually dismissed via the close button, focus should return to the element that originally triggered it. Use the `trigger` attribute to specify the `id` of that element, or the `triggerElement` property to pass a direct element reference. The `trigger` attribute takes precedence when both are set.
|
|
309
|
+
|
|
310
|
+
<div class="exampleWrapper">
|
|
311
|
+
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../apiExamples/trigger.html) -->
|
|
312
|
+
<!-- The below content is automatically added from ./../apiExamples/trigger.html -->
|
|
313
|
+
<p>Use the <code>trigger</code> attribute to pass the <code>id</code> of the element that opened the toast. When the toast is manually closed, focus will return to that element.</p>
|
|
314
|
+
<auro-button id="triggerAttrBtn">
|
|
315
|
+
Show notification
|
|
316
|
+
</auro-button>
|
|
317
|
+
<!--
|
|
318
|
+
NOTE: The manually added style is NOT necessary for use,
|
|
319
|
+
Demo purposes ONLY!
|
|
320
|
+
-->
|
|
321
|
+
<auro-toast style="display: block; margin: 0.5rem 0;" id="triggerAttrToast" trigger="triggerAttrBtn" disableAutoHide>
|
|
322
|
+
Flight booked successfully
|
|
323
|
+
</auro-toast>
|
|
324
|
+
<p>Use the <code>triggerElement</code> property to pass a direct reference to the element that opened the toast. Useful when an <code>id</code> is not available or when working programmatically.</p>
|
|
325
|
+
<auro-button id="triggerPropBtn">
|
|
326
|
+
Show notification
|
|
327
|
+
</auro-button>
|
|
328
|
+
<auro-toast style="display: block; margin: 0.5rem 0;" id="triggerPropToast" disableAutoHide>
|
|
329
|
+
Flight booked successfully.
|
|
330
|
+
</auro-toast>
|
|
331
|
+
<p>When both <code>trigger</code> and <code>triggerElement</code> are set, <code>trigger</code> takes precedence. In this example, <code>triggerElement</code> points to the second button but <code>trigger</code> points to the first — focus returns to the first button on close.</p>
|
|
332
|
+
<auro-button id="triggerPrecedenceBtn1">
|
|
333
|
+
Button 1 (trigger attribute target)
|
|
334
|
+
</auro-button>
|
|
335
|
+
<auro-button id="triggerPrecedenceBtn2">
|
|
336
|
+
Button 2 (triggerElement target — ignored)
|
|
337
|
+
</auro-button>
|
|
338
|
+
<auro-toast style="display: block; margin: 0.5rem 0;" id="triggerPrecedenceToast" trigger="triggerPrecedenceBtn1" disableAutoHide>
|
|
339
|
+
Flight booked successfully.
|
|
340
|
+
</auro-toast>
|
|
341
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
342
|
+
</div>
|
|
343
|
+
<auro-accordion alignRight>
|
|
344
|
+
<span slot="trigger">See code</span>
|
|
345
|
+
<!-- AURO-GENERATED-CONTENT:START (CODE:src=./../apiExamples/trigger.html) -->
|
|
346
|
+
<!-- The below code snippet is automatically added from ./../apiExamples/trigger.html -->
|
|
347
|
+
|
|
348
|
+
```html
|
|
349
|
+
<p>Use the <code>trigger</code> attribute to pass the <code>id</code> of the element that opened the toast. When the toast is manually closed, focus will return to that element.</p>
|
|
350
|
+
<auro-button id="triggerAttrBtn">
|
|
351
|
+
Show notification
|
|
352
|
+
</auro-button>
|
|
353
|
+
<!--
|
|
354
|
+
NOTE: The manually added style is NOT necessary for use,
|
|
355
|
+
Demo purposes ONLY!
|
|
356
|
+
-->
|
|
357
|
+
<auro-toast style="display: block; margin: 0.5rem 0;" id="triggerAttrToast" trigger="triggerAttrBtn" disableAutoHide>
|
|
358
|
+
Flight booked successfully
|
|
359
|
+
</auro-toast>
|
|
360
|
+
<p>Use the <code>triggerElement</code> property to pass a direct reference to the element that opened the toast. Useful when an <code>id</code> is not available or when working programmatically.</p>
|
|
361
|
+
<auro-button id="triggerPropBtn">
|
|
362
|
+
Show notification
|
|
363
|
+
</auro-button>
|
|
364
|
+
<auro-toast style="display: block; margin: 0.5rem 0;" id="triggerPropToast" disableAutoHide>
|
|
365
|
+
Flight booked successfully.
|
|
366
|
+
</auro-toast>
|
|
367
|
+
<p>When both <code>trigger</code> and <code>triggerElement</code> are set, <code>trigger</code> takes precedence. In this example, <code>triggerElement</code> points to the second button but <code>trigger</code> points to the first — focus returns to the first button on close.</p>
|
|
368
|
+
<auro-button id="triggerPrecedenceBtn1">
|
|
369
|
+
Button 1 (trigger attribute target)
|
|
370
|
+
</auro-button>
|
|
371
|
+
<auro-button id="triggerPrecedenceBtn2">
|
|
372
|
+
Button 2 (triggerElement target — ignored)
|
|
373
|
+
</auro-button>
|
|
374
|
+
<auro-toast style="display: block; margin: 0.5rem 0;" id="triggerPrecedenceToast" trigger="triggerPrecedenceBtn1" disableAutoHide>
|
|
375
|
+
Flight booked successfully.
|
|
376
|
+
</auro-toast>
|
|
377
|
+
```
|
|
378
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
379
|
+
<!-- AURO-GENERATED-CONTENT:START (CODE:src=./../apiExamples/trigger.js) -->
|
|
380
|
+
<!-- The below code snippet is automatically added from ./../apiExamples/trigger.js -->
|
|
381
|
+
|
|
382
|
+
```js
|
|
383
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
384
|
+
|
|
385
|
+
export function initTriggerExample() {
|
|
386
|
+
// trigger attribute — pass element id as a string
|
|
387
|
+
const attrBtn = document.querySelector("#triggerAttrBtn");
|
|
388
|
+
const attrToast = document.querySelector("#triggerAttrToast");
|
|
389
|
+
|
|
390
|
+
attrBtn.addEventListener("click", () => {
|
|
391
|
+
if (!attrToast.hasAttribute("visible")) {
|
|
392
|
+
attrToast.setAttribute("visible", true);
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
// triggerElement property — pass a direct element reference
|
|
397
|
+
const propBtn = document.querySelector("#triggerPropBtn");
|
|
398
|
+
const propToast = document.querySelector("#triggerPropToast");
|
|
399
|
+
|
|
400
|
+
propBtn.addEventListener("click", () => {
|
|
401
|
+
if (!propToast.hasAttribute("visible")) {
|
|
402
|
+
propToast.triggerElement = propBtn;
|
|
403
|
+
propToast.setAttribute("visible", true);
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
// precedence — trigger attribute wins over triggerElement when both are set
|
|
408
|
+
const precedenceBtn1 = document.querySelector("#triggerPrecedenceBtn1");
|
|
409
|
+
const precedenceBtn2 = document.querySelector("#triggerPrecedenceBtn2");
|
|
410
|
+
const precedenceToast = document.querySelector("#triggerPrecedenceToast");
|
|
411
|
+
|
|
412
|
+
precedenceBtn1.addEventListener("click", () => {
|
|
413
|
+
if (!precedenceToast.hasAttribute("visible")) {
|
|
414
|
+
precedenceToast.triggerElement = precedenceBtn2;
|
|
415
|
+
precedenceToast.setAttribute("visible", true);
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
precedenceBtn2.addEventListener("click", () => {
|
|
420
|
+
if (!precedenceToast.hasAttribute("visible")) {
|
|
421
|
+
precedenceToast.triggerElement = precedenceBtn2;
|
|
422
|
+
precedenceToast.setAttribute("visible", true);
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
```
|
|
427
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
428
|
+
</auro-accordion>
|
|
429
|
+
|
|
296
430
|
## Common Usage Patterns & Functional Examples
|
|
297
431
|
|
|
298
432
|
### Multiple Toasts
|
|
@@ -306,9 +440,9 @@ The multi-notification use case requires the use of the `<auro-toaster>` compone
|
|
|
306
440
|
<auro-button id="multiToastBtn-error">Show error toast</auro-button>
|
|
307
441
|
<auro-button id="multiToastBtn-success">Show success toast</auro-button>
|
|
308
442
|
<auro-toaster>
|
|
309
|
-
<auro-toast id="multiToast-default">Default toast
|
|
310
|
-
<auro-toast id="multiToast-error" variant="error">Unable to add lap infant. Please try again
|
|
311
|
-
<auro-toast id="multiToast-success" variant="success">Successfully added lap infant
|
|
443
|
+
<auro-toast id="multiToast-default">Default toast.</auro-toast>
|
|
444
|
+
<auro-toast id="multiToast-error" variant="error">Unable to add lap infant. Please try again.</auro-toast>
|
|
445
|
+
<auro-toast id="multiToast-success" variant="success">Successfully added lap infant.</auro-toast>
|
|
312
446
|
</auro-toaster>
|
|
313
447
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
314
448
|
</div>
|
|
@@ -322,9 +456,9 @@ The multi-notification use case requires the use of the `<auro-toaster>` compone
|
|
|
322
456
|
<auro-button id="multiToastBtn-error">Show error toast</auro-button>
|
|
323
457
|
<auro-button id="multiToastBtn-success">Show success toast</auro-button>
|
|
324
458
|
<auro-toaster>
|
|
325
|
-
<auro-toast id="multiToast-default">Default toast
|
|
326
|
-
<auro-toast id="multiToast-error" variant="error">Unable to add lap infant. Please try again
|
|
327
|
-
<auro-toast id="multiToast-success" variant="success">Successfully added lap infant
|
|
459
|
+
<auro-toast id="multiToast-default">Default toast.</auro-toast>
|
|
460
|
+
<auro-toast id="multiToast-error" variant="error">Unable to add lap infant. Please try again.</auro-toast>
|
|
461
|
+
<auro-toast id="multiToast-success" variant="success">Successfully added lap infant.</auro-toast>
|
|
328
462
|
</auro-toaster>
|
|
329
463
|
```
|
|
330
464
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
@@ -364,25 +498,47 @@ The dynamic notification use case requires the use of the `<auro-toaster>` compo
|
|
|
364
498
|
/* eslint-disable jsdoc/require-jsdoc */
|
|
365
499
|
|
|
366
500
|
const toastDefs = [
|
|
367
|
-
{ id: "dynamicToast-default", variant: null, message: "Default toast", btnId: "dynamicToastBtn-default" },
|
|
368
|
-
{ id: "dynamicToast-error", variant: "error", message: "Unable to add lap infant. Please try again", btnId: "dynamicToastBtn-error" },
|
|
369
|
-
{ id: "dynamicToast-success", variant: "success", message: "Successfully added lap infant", btnId: "dynamicToastBtn-success" },
|
|
501
|
+
{ id: "dynamicToast-default", variant: null, message: "Default toast.", btnId: "dynamicToastBtn-default" },
|
|
502
|
+
{ id: "dynamicToast-error", variant: "error", message: "Unable to add lap infant. Please try again.", btnId: "dynamicToastBtn-error" },
|
|
503
|
+
{ id: "dynamicToast-success", variant: "success", message: "Successfully added lap infant.", btnId: "dynamicToastBtn-success" },
|
|
370
504
|
];
|
|
371
505
|
|
|
506
|
+
// simple in-memory registry of active toasts
|
|
507
|
+
const activeToasts = new Map();
|
|
508
|
+
|
|
509
|
+
function generateToastId(baseId) {
|
|
510
|
+
return `${baseId}-${crypto.randomUUID()}`;
|
|
511
|
+
}
|
|
512
|
+
|
|
372
513
|
export function initDynamicToastsExample() {
|
|
373
514
|
const toaster = document.querySelector("#dynamicToaster");
|
|
374
515
|
|
|
375
|
-
toastDefs.forEach(({ id, variant, message, btnId }) => {
|
|
516
|
+
toastDefs.forEach(({ id: baseId, variant, message, btnId }) => {
|
|
376
517
|
document.querySelector(`#${btnId}`).addEventListener("click", () => {
|
|
377
518
|
const toast = document.createElement("auro-toast");
|
|
378
|
-
|
|
519
|
+
|
|
520
|
+
const toastId = generateToastId(baseId);
|
|
521
|
+
|
|
522
|
+
toast.id = toastId;
|
|
523
|
+
|
|
379
524
|
if (variant) {
|
|
380
525
|
toast.setAttribute("variant", variant);
|
|
381
526
|
}
|
|
527
|
+
|
|
382
528
|
toast.setAttribute("visible", true);
|
|
383
529
|
toast.textContent = message;
|
|
530
|
+
|
|
384
531
|
toaster.appendChild(toast);
|
|
385
|
-
|
|
532
|
+
|
|
533
|
+
// 👇 now the ID is actually used meaningfully
|
|
534
|
+
activeToasts.set(toastId, toast);
|
|
535
|
+
|
|
536
|
+
console.log("Toast added:", toastId);
|
|
537
|
+
|
|
538
|
+
// optional cleanup if your component doesn't auto-remove itself
|
|
539
|
+
toast.addEventListener("hide", () => {
|
|
540
|
+
activeToasts.delete(toastId);
|
|
541
|
+
});
|
|
386
542
|
});
|
|
387
543
|
});
|
|
388
544
|
}
|
|
@@ -390,6 +546,56 @@ export function initDynamicToastsExample() {
|
|
|
390
546
|
<!-- AURO-GENERATED-CONTENT:END -->
|
|
391
547
|
</auro-accordion>
|
|
392
548
|
|
|
549
|
+
### Dynamic Injection of Standalone Toasts without auro-toaster
|
|
550
|
+
|
|
551
|
+
When dynamically injecting `auro-toast` elements at runtime, the consumer is responsible for a container element with `aria-live` that **must already be present in the DOM** before any toast is appended to it. Screen readers register a live region when it first encounters the element on the page — content added to it later will trigger an announcement. If a live region and toast content enter the DOM at the same time, the screen reader has no opportunity to register the region first and will **not** announce the content.
|
|
552
|
+
|
|
553
|
+
The required pattern is a persistent container — a `div` or equivalent — with `aria-live="polite"` or `aria-live="assertive"`* that remains in the DOM at all times. Your application logic then injects `auro-toast` elements into this container at runtime as notifications occur.
|
|
554
|
+
|
|
555
|
+
**Warning:** Avoid applying `display: none` to a live region while it is in use. This removes it from the accessibility tree, preventing screen readers from detecting updates. Any announcements triggered during that time will be lost.
|
|
556
|
+
|
|
557
|
+
`auro-toast` automatically detects any ancestor live region at connection time. When one is found, it defers to that region and does not add its own role, preventing nested live regions.
|
|
558
|
+
|
|
559
|
+
\* Only use `aria-live="assertive"` if your UI is making use of toasts that are alerting the user of important information. If you are not using `auro-toaster` you are responsible for managing the changes between `assertive` and `polite` announcement states.
|
|
560
|
+
|
|
561
|
+
<div class="exampleWrapper">
|
|
562
|
+
<!-- AURO-GENERATED-CONTENT:START (FILE:src=./../apiExamples/standalone-toast.html) -->
|
|
563
|
+
<!-- The below content is automatically added from ./../apiExamples/standalone-toast.html -->
|
|
564
|
+
<auro-button id="standaloneToastBtn">Show toast</auro-button>
|
|
565
|
+
<div id="standaloneContainer" aria-live="polite" aria-atomic="false"></div>
|
|
566
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
567
|
+
</div>
|
|
568
|
+
<auro-accordion alignRight>
|
|
569
|
+
<span slot="trigger">See code</span>
|
|
570
|
+
<!-- AURO-GENERATED-CONTENT:START (CODE:src=./../apiExamples/standalone-toast.html) -->
|
|
571
|
+
<!-- The below code snippet is automatically added from ./../apiExamples/standalone-toast.html -->
|
|
572
|
+
|
|
573
|
+
```html
|
|
574
|
+
<auro-button id="standaloneToastBtn">Show toast</auro-button>
|
|
575
|
+
<div id="standaloneContainer" aria-live="polite" aria-atomic="false"></div>
|
|
576
|
+
```
|
|
577
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
578
|
+
<!-- AURO-GENERATED-CONTENT:START (CODE:src=./../apiExamples/standalone-toast.js) -->
|
|
579
|
+
<!-- The below code snippet is automatically added from ./../apiExamples/standalone-toast.js -->
|
|
580
|
+
|
|
581
|
+
```js
|
|
582
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
583
|
+
|
|
584
|
+
export function initStandaloneToastExample() {
|
|
585
|
+
const container = document.querySelector("#standaloneContainer");
|
|
586
|
+
|
|
587
|
+
document.querySelector("#standaloneToastBtn").addEventListener("click", () => {
|
|
588
|
+
const toast = document.createElement("auro-toast");
|
|
589
|
+
toast.setAttribute("visible", "");
|
|
590
|
+
toast.setAttribute("variant", "success");
|
|
591
|
+
toast.textContent = "Successfully added lap infant";
|
|
592
|
+
container.appendChild(toast);
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
```
|
|
596
|
+
<!-- AURO-GENERATED-CONTENT:END -->
|
|
597
|
+
</auro-accordion>
|
|
598
|
+
|
|
393
599
|
## Restyle Component with CSS Variables
|
|
394
600
|
|
|
395
601
|
The component may be restyled by changing the values of the following token(s).
|
package/demo/api.min.js
CHANGED
|
@@ -104,6 +104,7 @@ function initMultipleToastsExample() {
|
|
|
104
104
|
|
|
105
105
|
btn.addEventListener("click", () => {
|
|
106
106
|
if (!toast.hasAttribute("visible")) {
|
|
107
|
+
toast.triggerElement = btn;
|
|
107
108
|
toast.setAttribute("visible", true);
|
|
108
109
|
}
|
|
109
110
|
});
|
|
@@ -113,6 +114,7 @@ function initMultipleToastsExample() {
|
|
|
113
114
|
|
|
114
115
|
btnTwo.addEventListener("click", () => {
|
|
115
116
|
if (!toastTwo.hasAttribute("visible")) {
|
|
117
|
+
toastTwo.triggerElement = btnTwo;
|
|
116
118
|
toastTwo.setAttribute("visible", true);
|
|
117
119
|
}
|
|
118
120
|
});
|
|
@@ -122,6 +124,7 @@ function initMultipleToastsExample() {
|
|
|
122
124
|
|
|
123
125
|
btnThree.addEventListener("click", () => {
|
|
124
126
|
if (!toastThree.hasAttribute("visible")) {
|
|
127
|
+
toastThree.triggerElement = btnThree;
|
|
125
128
|
toastThree.setAttribute("visible", true);
|
|
126
129
|
}
|
|
127
130
|
});
|
|
@@ -130,29 +133,109 @@ function initMultipleToastsExample() {
|
|
|
130
133
|
/* eslint-disable jsdoc/require-jsdoc */
|
|
131
134
|
|
|
132
135
|
const toastDefs = [
|
|
133
|
-
{ id: "dynamicToast-default", variant: null, message: "Default toast", btnId: "dynamicToastBtn-default" },
|
|
134
|
-
{ id: "dynamicToast-error", variant: "error", message: "Unable to add lap infant. Please try again", btnId: "dynamicToastBtn-error" },
|
|
135
|
-
{ id: "dynamicToast-success", variant: "success", message: "Successfully added lap infant", btnId: "dynamicToastBtn-success" },
|
|
136
|
+
{ id: "dynamicToast-default", variant: null, message: "Default toast.", btnId: "dynamicToastBtn-default" },
|
|
137
|
+
{ id: "dynamicToast-error", variant: "error", message: "Unable to add lap infant. Please try again.", btnId: "dynamicToastBtn-error" },
|
|
138
|
+
{ id: "dynamicToast-success", variant: "success", message: "Successfully added lap infant.", btnId: "dynamicToastBtn-success" },
|
|
136
139
|
];
|
|
137
140
|
|
|
141
|
+
// simple in-memory registry of active toasts
|
|
142
|
+
const activeToasts = new Map();
|
|
143
|
+
|
|
144
|
+
function generateToastId(baseId) {
|
|
145
|
+
return `${baseId}-${crypto.randomUUID()}`;
|
|
146
|
+
}
|
|
147
|
+
|
|
138
148
|
function initDynamicToastsExample() {
|
|
139
149
|
const toaster = document.querySelector("#dynamicToaster");
|
|
140
150
|
|
|
141
|
-
toastDefs.forEach(({ id, variant, message, btnId }) => {
|
|
151
|
+
toastDefs.forEach(({ id: baseId, variant, message, btnId }) => {
|
|
142
152
|
document.querySelector(`#${btnId}`).addEventListener("click", () => {
|
|
143
153
|
const toast = document.createElement("auro-toast");
|
|
144
|
-
|
|
154
|
+
|
|
155
|
+
const toastId = generateToastId(baseId);
|
|
156
|
+
|
|
157
|
+
toast.id = toastId;
|
|
158
|
+
|
|
145
159
|
if (variant) {
|
|
146
160
|
toast.setAttribute("variant", variant);
|
|
147
161
|
}
|
|
162
|
+
|
|
148
163
|
toast.setAttribute("visible", true);
|
|
149
164
|
toast.textContent = message;
|
|
165
|
+
|
|
150
166
|
toaster.appendChild(toast);
|
|
151
|
-
|
|
167
|
+
|
|
168
|
+
// 👇 now the ID is actually used meaningfully
|
|
169
|
+
activeToasts.set(toastId, toast);
|
|
170
|
+
|
|
171
|
+
console.log("Toast added:", toastId);
|
|
172
|
+
|
|
173
|
+
// optional cleanup if your component doesn't auto-remove itself
|
|
174
|
+
toast.addEventListener("hide", () => {
|
|
175
|
+
activeToasts.delete(toastId);
|
|
176
|
+
});
|
|
152
177
|
});
|
|
153
178
|
});
|
|
154
179
|
}
|
|
155
180
|
|
|
181
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
182
|
+
|
|
183
|
+
function initStandaloneToastExample() {
|
|
184
|
+
const container = document.querySelector("#standaloneContainer");
|
|
185
|
+
|
|
186
|
+
document.querySelector("#standaloneToastBtn").addEventListener("click", () => {
|
|
187
|
+
const toast = document.createElement("auro-toast");
|
|
188
|
+
toast.setAttribute("visible", "");
|
|
189
|
+
toast.setAttribute("variant", "success");
|
|
190
|
+
toast.textContent = "Successfully added lap infant";
|
|
191
|
+
container.appendChild(toast);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/* eslint-disable jsdoc/require-jsdoc */
|
|
196
|
+
|
|
197
|
+
function initTriggerExample() {
|
|
198
|
+
// trigger attribute — pass element id as a string
|
|
199
|
+
const attrBtn = document.querySelector("#triggerAttrBtn");
|
|
200
|
+
const attrToast = document.querySelector("#triggerAttrToast");
|
|
201
|
+
|
|
202
|
+
attrBtn.addEventListener("click", () => {
|
|
203
|
+
if (!attrToast.hasAttribute("visible")) {
|
|
204
|
+
attrToast.setAttribute("visible", true);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// triggerElement property — pass a direct element reference
|
|
209
|
+
const propBtn = document.querySelector("#triggerPropBtn");
|
|
210
|
+
const propToast = document.querySelector("#triggerPropToast");
|
|
211
|
+
|
|
212
|
+
propBtn.addEventListener("click", () => {
|
|
213
|
+
if (!propToast.hasAttribute("visible")) {
|
|
214
|
+
propToast.triggerElement = propBtn;
|
|
215
|
+
propToast.setAttribute("visible", true);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// precedence — trigger attribute wins over triggerElement when both are set
|
|
220
|
+
const precedenceBtn1 = document.querySelector("#triggerPrecedenceBtn1");
|
|
221
|
+
const precedenceBtn2 = document.querySelector("#triggerPrecedenceBtn2");
|
|
222
|
+
const precedenceToast = document.querySelector("#triggerPrecedenceToast");
|
|
223
|
+
|
|
224
|
+
precedenceBtn1.addEventListener("click", () => {
|
|
225
|
+
if (!precedenceToast.hasAttribute("visible")) {
|
|
226
|
+
precedenceToast.triggerElement = precedenceBtn2;
|
|
227
|
+
precedenceToast.setAttribute("visible", true);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
precedenceBtn2.addEventListener("click", () => {
|
|
232
|
+
if (!precedenceToast.hasAttribute("visible")) {
|
|
233
|
+
precedenceToast.triggerElement = precedenceBtn2;
|
|
234
|
+
precedenceToast.setAttribute("visible", true);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
156
239
|
AuroToast.register();
|
|
157
240
|
AuroToaster.register();
|
|
158
241
|
|
|
@@ -173,6 +256,8 @@ function initExamples(initCount) {
|
|
|
173
256
|
initVisibleExample();
|
|
174
257
|
initMultipleToastsExample();
|
|
175
258
|
initDynamicToastsExample();
|
|
259
|
+
initStandaloneToastExample();
|
|
260
|
+
initTriggerExample();
|
|
176
261
|
} catch (_err) {
|
|
177
262
|
if (initCount <= 20) {
|
|
178
263
|
// setTimeout handles issue where content is sometimes loaded after the functions get called
|