File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -13,16 +13,26 @@ module.exports = React.createClass({
13
13
getInitialState : function ( ) {
14
14
return { open : false }
15
15
} ,
16
+ handleItemClick : function ( item ) {
17
+ this . setState ( {
18
+ open : false ,
19
+ itemTitle : item
20
+ } ) ;
21
+ } ,
16
22
render : function ( ) {
17
23
var list = this . props . items . map ( function ( item ) {
18
- return < ListItem item = { item } />
19
- } ) ;
24
+ return < ListItem
25
+ item = { item }
26
+ whenItemClicked = { this . handleItemClick }
27
+ className = { this . state . itemTitle === item ? "active" : "" }
28
+ />
29
+ } . bind ( this ) ) ;
20
30
21
31
return < div className = "dropdown" >
22
32
< Button
23
33
whenClicked = { this . handleClick }
24
34
className = "btn-default"
25
- title = { this . props . title }
35
+ title = { this . state . itemTitle || this . props . title }
26
36
subTitleClassName = "caret"
27
37
/>
28
38
< ul className = { "dropdown-menu " + ( this . state . open ? "show" : "" ) } >
Original file line number Diff line number Diff line change 1
1
var React = require ( 'react' ) ;
2
2
3
3
module . exports = React . createClass ( {
4
+ handleClick : function ( ) {
5
+ this . props . whenItemClicked ( this . props . item ) ;
6
+ } ,
4
7
render : function ( ) {
5
- return < li > < a > { this . props . item } </ a > </ li >
8
+ return < li className = { this . props . className } >
9
+ < a onClick = { this . handleClick } > { this . props . item } </ a >
10
+ </ li >
6
11
}
7
12
} ) ;
You can’t perform that action at this time.
0 commit comments