@@ -288,6 +288,7 @@ class ReactTooltip extends React.Component {
288
288
}
289
289
290
290
target . addEventListener ( 'mouseenter' , this . showTooltip , isCaptureMode ) ;
291
+ target . addEventListener ( 'focus' , this . showTooltip , isCaptureMode ) ;
291
292
if ( effect === 'float' ) {
292
293
target . addEventListener (
293
294
'mousemove' ,
@@ -296,6 +297,7 @@ class ReactTooltip extends React.Component {
296
297
) ;
297
298
}
298
299
target . addEventListener ( 'mouseleave' , this . hideTooltip , isCaptureMode ) ;
300
+ target . addEventListener ( 'blur' , this . showTooltip , isCaptureMode ) ;
299
301
} ) ;
300
302
}
301
303
@@ -401,6 +403,11 @@ class ReactTooltip extends React.Component {
401
403
scrollHide = this . props . scrollHide ;
402
404
}
403
405
406
+ // adding aria-describedby to target to make tooltips read by screen readers
407
+ if ( e && e . currentTarget && e . currentTarget . setAttribute ) {
408
+ e . currentTarget . setAttribute ( 'aria-describedby' , this . state . uuid ) ;
409
+ }
410
+
404
411
// Make sure the correct place is set
405
412
const desiredPlace =
406
413
e . currentTarget . getAttribute ( 'data-place' ) || this . props . place || 'top' ;
@@ -621,6 +628,11 @@ class ReactTooltip extends React.Component {
621
628
if ( ! isMyElement || ! this . state . show ) return ;
622
629
}
623
630
631
+ // clean up aria-describedby when hiding tooltip
632
+ if ( e && e . currentTarget && e . currentTarget . removeAttribute ) {
633
+ e . currentTarget . removeAttribute ( 'aria-describedby' ) ;
634
+ }
635
+
624
636
const resetState = ( ) => {
625
637
const isVisible = this . state . show ;
626
638
// Check if the mouse is actually over the tooltip, if so don't hide the tooltip
@@ -737,7 +749,7 @@ class ReactTooltip extends React.Component {
737
749
}
738
750
739
751
render ( ) {
740
- const { extraClass, html, ariaProps, disable } = this . state ;
752
+ const { extraClass, html, ariaProps, disable, uuid } = this . state ;
741
753
const content = this . getTooltipContent ( ) ;
742
754
const isEmptyTip = this . isEmptyTip ( content ) ;
743
755
const style = generateTooltipStyle (
@@ -773,7 +785,7 @@ class ReactTooltip extends React.Component {
773
785
return (
774
786
< Wrapper
775
787
className = { `${ wrapperClassName } ` }
776
- id = { this . props . id }
788
+ id = { this . props . id || uuid }
777
789
ref = { ref => ( this . tooltipRef = ref ) }
778
790
{ ...ariaProps }
779
791
data-id = "tooltip"
@@ -784,7 +796,7 @@ class ReactTooltip extends React.Component {
784
796
return (
785
797
< Wrapper
786
798
className = { `${ wrapperClassName } ` }
787
- id = { this . props . id }
799
+ id = { this . props . id || uuid }
788
800
{ ...ariaProps }
789
801
ref = { ref => ( this . tooltipRef = ref ) }
790
802
data-id = "tooltip"
0 commit comments