@@ -47,6 +47,7 @@ export default React.createClass({
47
47
classNames : PropTypes . object ,
48
48
defaultFilter : PropTypes . string ,
49
49
disabled : PropTypes . bool ,
50
+ groupProp : PropTypes . string ,
50
51
placeholder : PropTypes . string ,
51
52
selectedOptions : PropTypes . array ,
52
53
size : PropTypes . number ,
@@ -61,6 +62,7 @@ export default React.createClass({
61
62
classNames : { } ,
62
63
defaultFilter : '' ,
63
64
disabled : false ,
65
+ groupProp : false ,
64
66
placeholder : 'type to filter' ,
65
67
size : 6 ,
66
68
selectedOptions : [ ] ,
@@ -185,8 +187,31 @@ export default React.createClass({
185
187
186
188
render ( ) {
187
189
let { filter, filteredOptions, selectedValues} = this . state
188
- let { className, disabled, placeholder, size, textProp, valueProp} = this . props
190
+ let { className, disabled, groupProp , placeholder, size, textProp, valueProp} = this . props
189
191
let hasSelectedOptions = selectedValues . length > 0
192
+ let options = [ ]
193
+ if ( groupProp ) {
194
+ let groups = filteredOptions . reduce ( ( option , result ) => {
195
+ if ( ! result [ option [ groupProp ] ] ) {
196
+ result [ option [ groupProp ] ] = [ ]
197
+ }
198
+ result [ option [ groupProp ] ] . push ( option )
199
+ return result
200
+ } , { } )
201
+ options = Object . keys ( groups ) . map ( ( group ) => {
202
+ return (
203
+ < optgroup label = { group } >
204
+ { groups [ group ] . map ( ( option ) => {
205
+ return < option key = { option [ valueProp ] } value = { option [ valueProp ] } > { option [ textProp ] } </ option >
206
+ } ) }
207
+ </ optgroup >
208
+ )
209
+ } )
210
+ } else {
211
+ options = filteredOptions . map ( ( option ) => {
212
+ return < option key = { option [ valueProp ] } value = { option [ valueProp ] } > { option [ textProp ] } </ option >
213
+ } )
214
+ }
190
215
return < div className = { className } >
191
216
< input
192
217
type = "text"
@@ -205,9 +230,7 @@ export default React.createClass({
205
230
onChange = { this . _updateSelectedValues }
206
231
onDoubleClick = { this . _addSelectedToSelection }
207
232
disabled = { disabled } >
208
- { filteredOptions . map ( ( option ) => {
209
- return < option key = { option [ valueProp ] } value = { option [ valueProp ] } > { option [ textProp ] } </ option >
210
- } ) }
233
+ { options }
211
234
</ select >
212
235
< button type = "button"
213
236
className = { this . _getClassName ( 'button' , hasSelectedOptions && 'buttonActive' ) }
0 commit comments