@@ -13,6 +13,7 @@ import isCapture from './decorators/isCapture'
13
13
/* Utils */
14
14
import getPosition from './utils/getPosition'
15
15
import getTipContent from './utils/getTipContent'
16
+ import { parseAria } from './utils/aria'
16
17
17
18
/* CSS */
18
19
import cssStyle from './style'
@@ -59,7 +60,8 @@ class ReactTooltip extends Component {
59
60
event : props . event || null ,
60
61
eventOff : props . eventOff || null ,
61
62
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
63
65
}
64
66
65
67
this . bind ( [
@@ -91,6 +93,18 @@ class ReactTooltip extends Component {
91
93
this . bindWindowEvents ( ) // Bind global event for static method
92
94
}
93
95
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
+
94
108
componentWillUnmount ( ) {
95
109
this . mount = false
96
110
@@ -343,7 +357,7 @@ class ReactTooltip extends Component {
343
357
}
344
358
345
359
render ( ) {
346
- const { placeholder, extraClass, html} = this . state
360
+ const { placeholder, extraClass, html, ariaProps } = this . state
347
361
let tooltipClass = classname (
348
362
'__react_component_tooltip' ,
349
363
{ 'show' : this . state . show } ,
@@ -363,12 +377,14 @@ class ReactTooltip extends Component {
363
377
if ( html ) {
364
378
return (
365
379
< div className = { `${ tooltipClass } ${ extraClass } ` }
380
+ { ...ariaProps }
366
381
data-id = 'tooltip'
367
382
dangerouslySetInnerHTML = { { __html : placeholder } } > </ div >
368
383
)
369
384
} else {
370
385
return (
371
386
< div className = { `${ tooltipClass } ${ extraClass } ` }
387
+ { ...ariaProps }
372
388
data-id = 'tooltip' > { placeholder } </ div >
373
389
)
374
390
}
0 commit comments