@@ -13,6 +13,7 @@ import isCapture from './decorators/isCapture'
1313/* Utils */
1414import getPosition from './utils/getPosition'
1515import getTipContent from './utils/getTipContent'
16+ import { parseAria } from './utils/aria'
1617
1718/* CSS */
1819import cssStyle from './style'
@@ -59,7 +60,8 @@ class ReactTooltip extends Component {
5960 event : props . event || null ,
6061 eventOff : props . eventOff || null ,
6162 currentEvent : null , // Current mouse event
62- currentTarget : null // Current target of mouse event
63+ currentTarget : null , // Current target of mouse event
64+ ariaProps : parseAria ( props ) // aria- and role attributes
6365 }
6466
6567 this . bind ( [
@@ -91,6 +93,18 @@ class ReactTooltip extends Component {
9193 this . bindWindowEvents ( ) // Bind global event for static method
9294 }
9395
96+ componentWillReceiveProps ( props ) {
97+ const { ariaProps } = this . state
98+ const newAriaProps = parseAria ( props )
99+
100+ const isChanged = Object . keys ( newAriaProps ) . some ( props => {
101+ return newAriaProps [ props ] !== ariaProps [ props ]
102+ } )
103+ if ( isChanged ) {
104+ this . setState ( { ariaProps : newAriaProps } )
105+ }
106+ }
107+
94108 componentWillUnmount ( ) {
95109 this . mount = false
96110
@@ -343,7 +357,7 @@ class ReactTooltip extends Component {
343357 }
344358
345359 render ( ) {
346- const { placeholder, extraClass, html} = this . state
360+ const { placeholder, extraClass, html, ariaProps } = this . state
347361 let tooltipClass = classname (
348362 '__react_component_tooltip' ,
349363 { 'show' : this . state . show } ,
@@ -363,12 +377,14 @@ class ReactTooltip extends Component {
363377 if ( html ) {
364378 return (
365379 < div className = { `${ tooltipClass } ${ extraClass } ` }
380+ { ...ariaProps }
366381 data-id = 'tooltip'
367382 dangerouslySetInnerHTML = { { __html : placeholder } } > </ div >
368383 )
369384 } else {
370385 return (
371386 < div className = { `${ tooltipClass } ${ extraClass } ` }
387+ { ...ariaProps }
372388 data-id = 'tooltip' > { placeholder } </ div >
373389 )
374390 }
0 commit comments