diff --git a/src/components/dropdown/Dropdown.js b/src/components/dropdown/Dropdown.js
index cb672fe919..e1e718e8ef 100644
--- a/src/components/dropdown/Dropdown.js
+++ b/src/components/dropdown/Dropdown.js
@@ -18,6 +18,7 @@ export class Dropdown extends Component {
filter:false,
filterBy:null,
filterPlaceholder:null,
+ editable:false,
placeholder:null
};
@@ -33,6 +34,7 @@ export class Dropdown extends Component {
filter:PropTypes.bool,
filterBy: PropTypes.string,
filterPlaceholder: PropTypes.string,
+ editable:PropTypes.bool,
placeholder: PropTypes.string
};
@@ -44,6 +46,8 @@ export class Dropdown extends Component {
this.onInputBlur=this.onInputBlur.bind(this);
this.onInputFocus=this.onInputFocus.bind(this);
this.onKeydown=this.onKeydown.bind(this);
+ this.onEditableInputClick=this.onEditableInputClick.bind(this);
+ this.onEditableInputFocus=this.onEditableInputFocus.bind(this);
}
componentDidMount() {
@@ -286,6 +290,23 @@ export class Dropdown extends Component {
this.documentClickListener = null;
}
}
+ onEditableInputFocus(event) {
+ this.setState({focus:true});
+ this.hide();
+ }
+
+ onEditableInputClick(event) {
+ this.optionClick = false;
+ event.stopPropagation();
+ }
+
+ onEditable(event){
+ this.editValue=event.target.value;
+ this.props.onChange({
+ originalEvent: event,
+ value: this.editValue
+ });
+ }
render() {
var styleClass = classNames('ui-dropdown ui-widget ui-state-default ui-corner-all', this.props.className, {
@@ -297,6 +318,7 @@ export class Dropdown extends Component {
var label = selectedOption ? selectedOption.label : (this.props.options ? this.props.options[0].label : null);
var listItems, optionElements;
var filterInput,filter;
+ var editable;
if(this.props.options) {
@@ -327,6 +349,12 @@ export class Dropdown extends Component {
filter=
this.onFilter(event)}
onClick={this.onFilterInputClick} >{filterInput}
}
+ if(this.props.editable){
+ editable= {this.editableInput = el;}} onChange={(event) => this.onEditable(event)}
+ onClick={this.onEditableInputClick} placeholder={this.props.placeholder}
+ onFocus={this.onEditableInputFocus} onBlur={this.onInputBlur} />
+ }
return (
{this.container = el;}} style={this.props.style}>
@@ -337,7 +365,8 @@ export class Dropdown extends Component {
{this.input = el;}} type="text" onFocus={this.onInputFocus}
onKeyDown={this.onKeydown} onBlur={this.onInputBlur}/>
-
+ {editable}
+ {!this.props.editable && }
diff --git a/src/showcase/dropdown/DropdownDemo.js b/src/showcase/dropdown/DropdownDemo.js
index 48bcff5520..4275adde5d 100644
--- a/src/showcase/dropdown/DropdownDemo.js
+++ b/src/showcase/dropdown/DropdownDemo.js
@@ -10,6 +10,7 @@ export class DropdownDemo extends Component {
super();
this.state = {};
this.onCityChange = this.onCityChange.bind(this);
+ this.onCarChange = this.onCarChange.bind(this);
this.onCarChange2 = this.onCarChange2.bind(this);
}
@@ -17,6 +18,10 @@ export class DropdownDemo extends Component {
this.setState({city: e.value});
}
+ onCarChange(e) {
+ this.setState({car: e.value});
+ }
+
onCarChange2(e) {
this.setState({car2: e.value});
}
@@ -73,6 +78,11 @@ export class DropdownDemo extends Component {
{this.state.city ? 'Selected City: ' + this.state.city : 'No city selected'}
+ Editable
+
+ {this.state.car ? 'Selected Car: ' + this.state.car : 'No car selected'}
+
Advanced
@@ -283,6 +293,12 @@ render() {
null |
Placeholder text to show when filter input is empty. |
+
+ editable |
+ boolean |
+ false |
+ When present, custom value instead of predefined options can be entered using the editable input field. |
+
placeholder |
string |
@@ -451,6 +467,10 @@ export class DropdownDemo extends Component {
{this.state.city ? 'Selected City: ' + this.state.city : 'No city selected'}
+ Editable
+
+ {this.state.car ? 'Selected Car: ' + this.state.car : 'No car selected'}
+
Advanced
{this.state.car2 ? 'Selected Car: ' + this.state.car2 : 'No car selected'}