From 2c735891f046729315d331d93409b3d003f4a0bb Mon Sep 17 00:00:00 2001 From: Darmody Date: Wed, 1 Mar 2017 00:05:02 +0800 Subject: [PATCH] add creatable option --- src/FilterMixin.js | 6 ++++-- src/Select.jsx | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/FilterMixin.js b/src/FilterMixin.js index 1ba314247..141999010 100644 --- a/src/FilterMixin.js +++ b/src/FilterMixin.js @@ -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); @@ -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); diff --git a/src/Select.jsx b/src/Select.jsx index fea251571..a9b16c435 100644 --- a/src/Select.jsx +++ b/src/Select.jsx @@ -77,6 +77,7 @@ const Select = React.createClass({ maxTagTextLength: PropTypes.number, tokenSeparators: PropTypes.arrayOf(PropTypes.string), getInputElement: PropTypes.func, + creatable: PropTypes.bool, }, mixins: [FilterMixin], @@ -105,6 +106,7 @@ const Select = React.createClass({ optionFilterProp: 'value', optionLabelProp: 'value', notFoundContent: 'Not Found', + creatable: false, }; },