Skip to content

Commit

Permalink
exploring state and events - part 6
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Mar 30, 2015
1 parent 3e8921a commit 3625a8d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 13 additions & 3 deletions dropdown/src/dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,26 @@ module.exports = React.createClass({
getInitialState: function(){
return { open: false }
},
handleItemClick: function(item) {
this.setState({
open: false,
itemTitle: item
});
},
render: function() {
var list = this.props.items.map(function(item){
return <ListItem item={item} />
});
return <ListItem
item={item}
whenItemClicked={this.handleItemClick}
className={this.state.itemTitle === item ? "active" : "" }
/>
}.bind(this));

return <div className="dropdown">
<Button
whenClicked={this.handleClick}
className="btn-default"
title={this.props.title}
title={this.state.itemTitle || this.props.title}
subTitleClassName="caret"
/>
<ul className={"dropdown-menu " + (this.state.open ? "show" : "") }>
Expand Down
7 changes: 6 additions & 1 deletion dropdown/src/list-item.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
var React = require('react');

module.exports = React.createClass({
handleClick: function() {
this.props.whenItemClicked(this.props.item);
},
render: function() {
return <li><a>{this.props.item}</a></li>
return <li className={this.props.className}>
<a onClick={this.handleClick}>{this.props.item}</a>
</li>
}
});

0 comments on commit 3625a8d

Please sign in to comment.