@@ -8,6 +8,11 @@ export interface ToastOptions extends BaseOptions {
8
8
* @default ""
9
9
*/
10
10
text : string ;
11
+ /**
12
+ * Element Id for the tooltip.
13
+ * @default ""
14
+ */
15
+ toastId ?: string ;
11
16
/**
12
17
* Length in ms the Toast stays before dismissal.
13
18
* @default 4000
@@ -53,7 +58,7 @@ let _defaults: ToastOptions = {
53
58
54
59
export class Toast {
55
60
/** The toast element. */
56
- el : HTMLDivElement ;
61
+ el : HTMLElement ;
57
62
/**
58
63
* The remaining amount of time in ms that the toast
59
64
* will stay before dismissal.
@@ -199,7 +204,10 @@ export class Toast {
199
204
}
200
205
201
206
_createToast ( ) {
202
- const toast = document . createElement ( 'div' ) ;
207
+ const toast = this . options . toastId
208
+ ? document . getElementById ( this . options . toastId )
209
+ : document . createElement ( 'div' ) ;
210
+ //const toast = document.createElement('div');
203
211
toast . classList . add ( 'toast' ) ;
204
212
toast . setAttribute ( 'role' , 'alert' ) ;
205
213
toast . setAttribute ( 'aria-live' , 'assertive' ) ;
@@ -211,7 +219,8 @@ export class Toast {
211
219
}
212
220
213
221
// Set text content
214
- toast . innerText = this . message ;
222
+ if ( this . message )
223
+ toast . innerText = this . message ;
215
224
216
225
// Append toast
217
226
Toast . _container . appendChild ( toast ) ;
@@ -220,6 +229,7 @@ export class Toast {
220
229
221
230
_animateIn ( ) {
222
231
// Animate toast in
232
+ this . el . style . display = ""
223
233
anim ( {
224
234
targets : this . el ,
225
235
top : 0 ,
@@ -273,10 +283,12 @@ export class Toast {
273
283
this . options . completeCallback ( ) ;
274
284
}
275
285
// Remove toast from DOM
276
- this . el . remove ( ) ;
277
- Toast . _toasts . splice ( Toast . _toasts . indexOf ( this ) , 1 ) ;
278
- if ( Toast . _toasts . length === 0 ) {
279
- Toast . _removeContainer ( ) ;
286
+ if ( ! this . options . toastId ) {
287
+ this . el . remove ( ) ;
288
+ Toast . _toasts . splice ( Toast . _toasts . indexOf ( this ) , 1 ) ;
289
+ if ( Toast . _toasts . length === 0 ) {
290
+ Toast . _removeContainer ( ) ;
291
+ }
280
292
}
281
293
}
282
294
} ) ;
0 commit comments