@@ -200,6 +200,7 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
200
200
} ) ,
201
201
) ;
202
202
window . clearTimeout ( this . autoCloseTimeoutId ) ;
203
+ this . autoCloseTimeoutId = null ;
203
204
window . clearTimeout ( this . queueTimeout ) ;
204
205
disconnectLocalized ( this ) ;
205
206
disconnectMessages ( this ) ;
@@ -226,13 +227,18 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
226
227
[ CSS . containerQueued ] : queued ,
227
228
[ `${ CSS . container } --${ placement } ` ] : true ,
228
229
[ CSS . containerSlottedInShell ] : this . slottedInShell ,
230
+ [ CSS . focused ] : this . keyBoardFocus ,
229
231
} }
230
232
onPointerEnter = { this . autoClose && this . autoCloseTimeoutId ? this . handleMouseOver : null }
231
- onPointerLeave = { this . autoClose && this . autoCloseTimeoutId ? this . handleMouseLeave : null }
233
+ onPointerLeave = { this . autoClose ? this . handleMouseLeave : null }
232
234
ref = { this . setTransitionEl }
233
235
>
234
236
{ effectiveIcon && this . renderIcon ( effectiveIcon ) }
235
- < div class = { CSS . textContainer } >
237
+ < div
238
+ class = { CSS . textContainer }
239
+ onFocusin = { this . autoClose && this . autoCloseTimeoutId ? this . handleKeyBoardFocus : null }
240
+ onFocusout = { this . autoClose ? this . handleKeyBoardBlur : null }
241
+ >
236
242
< slot name = { SLOTS . title } />
237
243
< slot name = { SLOTS . message } />
238
244
< slot name = { SLOTS . link } />
@@ -246,13 +252,27 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
246
252
) ;
247
253
}
248
254
255
+ private handleKeyBoardFocus = ( ) : void => {
256
+ this . keyBoardFocus = true ;
257
+ this . handleFocus ( ) ;
258
+ } ;
259
+
260
+ private handleKeyBoardBlur = ( ) : void => {
261
+ this . keyBoardFocus = false ;
262
+ if ( ! this . mouseFocus ) {
263
+ this . handleBlur ( ) ;
264
+ }
265
+ } ;
266
+
249
267
private renderCloseButton ( ) : VNode {
250
268
return (
251
269
< button
252
270
aria-label = { this . messages . close }
253
271
class = { CSS . close }
254
272
key = "close"
255
273
onClick = { this . closeAlert }
274
+ onFocusin = { this . autoClose ? this . handleKeyBoardFocus : null }
275
+ onFocusout = { this . autoClose ? this . handleKeyBoardBlur : null }
256
276
ref = { ( el ) => ( this . closeButton = el ) }
257
277
type = "button"
258
278
>
@@ -429,6 +449,8 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
429
449
/** is the alert queued */
430
450
@State ( ) queued = false ;
431
451
452
+ @State ( ) keyBoardFocus = false ;
453
+
432
454
private autoCloseTimeoutId : number = null ;
433
455
434
456
private closeButton : HTMLButtonElement ;
@@ -447,6 +469,8 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
447
469
448
470
transitionEl : HTMLDivElement ;
449
471
472
+ mouseFocus : boolean ;
473
+
450
474
//--------------------------------------------------------------------------
451
475
//
452
476
// Private Methods
@@ -510,12 +534,25 @@ export class Alert implements OpenCloseComponent, LoadableComponent, T9nComponen
510
534
} ;
511
535
512
536
private handleMouseOver = ( ) : void => {
537
+ this . mouseFocus = true ;
538
+ this . handleFocus ( ) ;
539
+ } ;
540
+
541
+ private handleMouseLeave = ( ) : void => {
542
+ this . mouseFocus = false ;
543
+ if ( ! this . keyBoardFocus ) {
544
+ this . handleBlur ( ) ;
545
+ }
546
+ } ;
547
+
548
+ private handleFocus = ( ) : void => {
513
549
window . clearTimeout ( this . autoCloseTimeoutId ) ;
550
+ this . autoCloseTimeoutId = null ;
514
551
this . totalOpenTime = Date . now ( ) - this . initialOpenTime ;
515
552
this . lastMouseOverBegin = Date . now ( ) ;
516
553
} ;
517
554
518
- private handleMouseLeave = ( ) : void => {
555
+ private handleBlur = ( ) : void => {
519
556
const hoverDuration = Date . now ( ) - this . lastMouseOverBegin ;
520
557
const timeRemaining =
521
558
DURATIONS [ this . autoCloseDuration ] - this . totalOpenTime + this . totalHoverTime ;
0 commit comments