@@ -47,6 +47,7 @@ export default React.createClass({
4747 classNames : PropTypes . object ,
4848 defaultFilter : PropTypes . string ,
4949 disabled : PropTypes . bool ,
50+ groupProp : PropTypes . string ,
5051 placeholder : PropTypes . string ,
5152 selectedOptions : PropTypes . array ,
5253 size : PropTypes . number ,
@@ -61,6 +62,7 @@ export default React.createClass({
6162 classNames : { } ,
6263 defaultFilter : '' ,
6364 disabled : false ,
65+ groupProp : false ,
6466 placeholder : 'type to filter' ,
6567 size : 6 ,
6668 selectedOptions : [ ] ,
@@ -185,8 +187,31 @@ export default React.createClass({
185187
186188 render ( ) {
187189 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
189191 let hasSelectedOptions = selectedValues . length > 0
192+ let options = [ ]
193+ if ( groupProp ) {
194+ let groups = filteredOptions . reduce ( ( result , option ) => {
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 key = { group } 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+ }
190215 return < div className = { className } >
191216 < input
192217 type = "text"
@@ -205,9 +230,7 @@ export default React.createClass({
205230 onChange = { this . _updateSelectedValues }
206231 onDoubleClick = { this . _addSelectedToSelection }
207232 disabled = { disabled } >
208- { filteredOptions . map ( ( option ) => {
209- return < option key = { option [ valueProp ] } value = { option [ valueProp ] } > { option [ textProp ] } </ option >
210- } ) }
233+ { options }
211234 </ select >
212235 < button type = "button"
213236 className = { this . _getClassName ( 'button' , hasSelectedOptions && 'buttonActive' ) }
0 commit comments