Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ Property | Type | Description
`newOptionCreator` | function | Factory to create new option. Expected signature: `({ label: string, labelKey: string, valueKey: string }): Object` |
`onNewOptionClick` | function | new option click handler, it calls when new option has been selected. `function(option) {}` |
`shouldKeyDownEventCreateNewOption` | function | Decides if a keyDown event (eg its `keyCode`) should result in the creation of a new option. ENTER, TAB and comma keys create new options by default. Expected signature: `({ keyCode: number }): boolean` |
`newOptionPosition` | string | Set the position of the new option. Expected value: 'bottom' or 'top' (default: 'top') |
`promptTextCreator` | function | Factory for overriding default option creator prompt label. By default it will read 'Create option "{label}"'. Expected signature: `(label: String): String` |

### Combining Async and Creatable
Expand Down
15 changes: 12 additions & 3 deletions src/Creatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ const Creatable = React.createClass({
// ({ label: string, labelKey: string, valueKey: string }): Object
newOptionCreator: React.PropTypes.func,

// input change handler: function (inputValue) {}
// Set the position of the new option.
// Expected value: 'bottom' or 'top'
newOptionPosition: React.PropTypes.string,

// input change handler: function (inputValue) {}
onInputChange: React.PropTypes.func,

// input keyDown handler: function (event) {}
Expand Down Expand Up @@ -67,6 +71,7 @@ const Creatable = React.createClass({
isValidNewOption,
menuRenderer: defaultMenuRenderer,
newOptionCreator,
newOptionPosition: 'top',
promptTextCreator,
shouldKeyDownEventCreateNewOption,
};
Expand Down Expand Up @@ -99,7 +104,7 @@ const Creatable = React.createClass({
},

filterOptions (...params) {
const { filterOptions, isValidNewOption, options, promptTextCreator } = this.props;
const { filterOptions, isValidNewOption, newOptionPosition, options, promptTextCreator } = this.props;

// TRICKY Check currently selected options as well.
// Don't display a create-prompt for a value that's selected.
Expand Down Expand Up @@ -133,7 +138,11 @@ const Creatable = React.createClass({
valueKey: this.valueKey
});

filteredOptions.unshift(this._createPlaceholderOption);
if (newOptionPosition === 'top') {
filteredOptions.unshift(this._createPlaceholderOption);
} else if (newOptionPosition === 'bottom') {
filteredOptions.push(this._createPlaceholderOption);
}
}
}

Expand Down