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
6 changes: 4 additions & 2 deletions src/FilterMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default {
const inputValue = iv === undefined ? this.state.inputValue : iv;
const childrenKeys = [];
const tags = props.tags;
const creatable = props.creatable;
React.Children.forEach(children, (child) => {
if (child.type.isSelectOptGroup) {
const innerItems = this.renderFilterOptionsFromChildren(child.props.children, false);
Expand Down Expand Up @@ -61,13 +62,14 @@ export default {
{...child.props}
/>);
}
if (tags && !child.props.disabled) {
if ((tags || creatable) && !child.props.disabled) {
childrenKeys.push(childValue);
}
});
if (tags) {
if (tags || creatable) {
// tags value must be string
let value = this.state.value || [];
value = Array.isArray(value) ? value : [value];
value = value.filter((singleValue) => {
return childrenKeys.indexOf(singleValue.key) === -1 &&
(!inputValue || String(singleValue.key).indexOf(String(inputValue)) > -1);
Expand Down
2 changes: 2 additions & 0 deletions src/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ const Select = React.createClass({
maxTagTextLength: PropTypes.number,
tokenSeparators: PropTypes.arrayOf(PropTypes.string),
getInputElement: PropTypes.func,
creatable: PropTypes.bool,
},

mixins: [FilterMixin],
Expand Down Expand Up @@ -105,6 +106,7 @@ const Select = React.createClass({
optionFilterProp: 'value',
optionLabelProp: 'value',
notFoundContent: 'Not Found',
creatable: false,
};
},

Expand Down