@@ -2,25 +2,13 @@ import React, { PropTypes } from 'react';
2
2
import { findDOMNode } from 'react-dom' ;
3
3
import cx from 'classnames' ;
4
4
5
- function syncNodeAttributes ( node , props ) {
6
- if ( props . selected ) {
7
- node . setAttribute ( 'tabindex' , '0' ) ;
8
- node . setAttribute ( 'selected' , 'selected' ) ;
9
- if ( props . focus ) {
10
- node . focus ( ) ;
11
- }
12
- } else {
13
- node . removeAttribute ( 'tabindex' ) ;
14
- node . removeAttribute ( 'selected' ) ;
15
- }
16
- }
17
-
18
5
module . exports = React . createClass ( {
19
6
displayName : 'Tab' ,
20
7
21
8
propTypes : {
22
9
className : PropTypes . string ,
23
10
id : PropTypes . string ,
11
+ focus : PropTypes . bool ,
24
12
selected : PropTypes . bool ,
25
13
disabled : PropTypes . bool ,
26
14
panelId : PropTypes . string ,
@@ -41,11 +29,17 @@ module.exports = React.createClass({
41
29
} ,
42
30
43
31
componentDidMount ( ) {
44
- syncNodeAttributes ( findDOMNode ( this ) , this . props ) ;
32
+ this . checkFocus ( ) ;
45
33
} ,
46
34
47
35
componentDidUpdate ( ) {
48
- syncNodeAttributes ( findDOMNode ( this ) , this . props ) ;
36
+ this . checkFocus ( ) ;
37
+ } ,
38
+
39
+ checkFocus ( ) {
40
+ if ( this . props . selected && this . props . focus ) {
41
+ findDOMNode ( this ) . focus ( ) ;
42
+ }
49
43
} ,
50
44
51
45
render ( ) {
@@ -68,6 +62,7 @@ module.exports = React.createClass({
68
62
aria-expanded = { selected ? 'true' : 'false' }
69
63
aria-disabled = { disabled ? 'true' : 'false' }
70
64
aria-controls = { panelId }
65
+ tabIndex = { selected ? '0' : null }
71
66
>
72
67
{ children }
73
68
</ li >
0 commit comments