@@ -2,25 +2,13 @@ import React, { PropTypes } from 'react';
22import { findDOMNode } from 'react-dom' ;
33import cx from 'classnames' ;
44
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-
185module . exports = React . createClass ( {
196 displayName : 'Tab' ,
207
218 propTypes : {
229 className : PropTypes . string ,
2310 id : PropTypes . string ,
11+ focus : PropTypes . bool ,
2412 selected : PropTypes . bool ,
2513 disabled : PropTypes . bool ,
2614 panelId : PropTypes . string ,
@@ -41,11 +29,17 @@ module.exports = React.createClass({
4129 } ,
4230
4331 componentDidMount ( ) {
44- syncNodeAttributes ( findDOMNode ( this ) , this . props ) ;
32+ this . checkFocus ( ) ;
4533 } ,
4634
4735 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+ }
4943 } ,
5044
5145 render ( ) {
@@ -68,6 +62,7 @@ module.exports = React.createClass({
6862 aria-expanded = { selected ? 'true' : 'false' }
6963 aria-disabled = { disabled ? 'true' : 'false' }
7064 aria-controls = { panelId }
65+ tabIndex = { selected ? '0' : null }
7166 >
7267 { children }
7368 </ li >
0 commit comments