@@ -288,6 +288,7 @@ class ReactTooltip extends React.Component {
288288 }
289289
290290 target . addEventListener ( 'mouseenter' , this . showTooltip , isCaptureMode ) ;
291+ target . addEventListener ( 'focus' , this . showTooltip , isCaptureMode ) ;
291292 if ( effect === 'float' ) {
292293 target . addEventListener (
293294 'mousemove' ,
@@ -296,6 +297,7 @@ class ReactTooltip extends React.Component {
296297 ) ;
297298 }
298299 target . addEventListener ( 'mouseleave' , this . hideTooltip , isCaptureMode ) ;
300+ target . addEventListener ( 'blur' , this . showTooltip , isCaptureMode ) ;
299301 } ) ;
300302 }
301303
@@ -401,6 +403,11 @@ class ReactTooltip extends React.Component {
401403 scrollHide = this . props . scrollHide ;
402404 }
403405
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+
404411 // Make sure the correct place is set
405412 const desiredPlace =
406413 e . currentTarget . getAttribute ( 'data-place' ) || this . props . place || 'top' ;
@@ -621,6 +628,11 @@ class ReactTooltip extends React.Component {
621628 if ( ! isMyElement || ! this . state . show ) return ;
622629 }
623630
631+ // clean up aria-describedby when hiding tooltip
632+ if ( e && e . currentTarget && e . currentTarget . removeAttribute ) {
633+ e . currentTarget . removeAttribute ( 'aria-describedby' ) ;
634+ }
635+
624636 const resetState = ( ) => {
625637 const isVisible = this . state . show ;
626638 // 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 {
737749 }
738750
739751 render ( ) {
740- const { extraClass, html, ariaProps, disable } = this . state ;
752+ const { extraClass, html, ariaProps, disable, uuid } = this . state ;
741753 const content = this . getTooltipContent ( ) ;
742754 const isEmptyTip = this . isEmptyTip ( content ) ;
743755 const style = generateTooltipStyle (
@@ -773,7 +785,7 @@ class ReactTooltip extends React.Component {
773785 return (
774786 < Wrapper
775787 className = { `${ wrapperClassName } ` }
776- id = { this . props . id }
788+ id = { this . props . id || uuid }
777789 ref = { ref => ( this . tooltipRef = ref ) }
778790 { ...ariaProps }
779791 data-id = "tooltip"
@@ -784,7 +796,7 @@ class ReactTooltip extends React.Component {
784796 return (
785797 < Wrapper
786798 className = { `${ wrapperClassName } ` }
787- id = { this . props . id }
799+ id = { this . props . id || uuid }
788800 { ...ariaProps }
789801 ref = { ref => ( this . tooltipRef = ref ) }
790802 data-id = "tooltip"
0 commit comments