Last active
December 17, 2015 08:35
-
-
Save khrtz/d6faee1056cba16762f0 to your computer and use it in GitHub Desktop.
Reactのタブ切り替え ex.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onMoveTab(e) { | |
const root = ReactDOM.findDOMNode(this.refs.filter) | |
$(root).find("li").remove("active") | |
$(e.target).closest("li")s.addClass("active") | |
this.props.onChangeCB($(e.target).closest("li").text()) | |
} | |
render () { | |
this.props.tabList.map((item, key) => { | |
className = key == this.state.index ? "active" : "" | |
return tabList.push( | |
<li key={key} className={ className } onClick={ this.onChange }>{ item }</li> | |
) | |
}) | |
} | |
// or | |
updateIndex(i, fn) { | |
this.setState({index: i}, () => { | |
React.findDOMNode(this.refs['tab' + i]).focus(); | |
}); | |
} | |
onMoveTab(e) { | |
const rawIndex = this.state.index; | |
} | |
this.props.tabList.map((item, key) => { | |
render ( | |
<li key={i}> | |
ref={'tab' + i} | |
tabIndex={rawIndex === i ? '0' : '-1'} | |
onKeyUp={this.onMoveTab.bind(this)} | |
onClick={this.onClickTab.bind(this, i)}> | |
{item} | |
</li> | |
) | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment