rc-select
Advanced tools
Comparing version 4.2.0 to 4.2.1
@@ -54,3 +54,3 @@ 'use strict'; | ||
function filterFn(input, child) { | ||
return child.props[this.props.optionFilterProp].indexOf(input) > -1; | ||
return this.getPropValue(child, this.props.optionFilterProp).indexOf(input) > -1; | ||
} | ||
@@ -92,2 +92,23 @@ | ||
}, { | ||
key: 'getValuePropValue', | ||
value: function getValuePropValue(c) { | ||
var props = c.props; | ||
if ('value' in props) { | ||
return props.value; | ||
} | ||
if (c.key) { | ||
return c.key; | ||
} | ||
throw new Error('no key or value for ' + c); | ||
} | ||
}, { | ||
key: 'getPropValue', | ||
value: function getPropValue(c, prop) { | ||
if (prop === 'value') { | ||
return this.getValuePropValue(c); | ||
} else { | ||
return c.props[prop]; | ||
} | ||
} | ||
}, { | ||
key: 'fireChange', | ||
@@ -108,3 +129,3 @@ value: function fireChange(value) { | ||
} | ||
var label; | ||
var label = null; | ||
React.Children.forEach(children, function (c) { | ||
@@ -116,4 +137,4 @@ if (c.type === OptGroup) { | ||
} | ||
} else if (c.props.value === value) { | ||
label = c.props[_this2.props.optionLabelProp]; | ||
} else if (_this2.getValuePropValue(c) === value) { | ||
label = _this2.getPropValue(c, _this2.props.optionLabelProp); | ||
} | ||
@@ -156,6 +177,8 @@ }); | ||
key = label; | ||
} else if (!label && key) { | ||
label = key; | ||
} | ||
sel.push(React.createElement( | ||
MenuItemGroup, | ||
{ key: key, title: child.props.label }, | ||
{ key: key, title: label }, | ||
innerItems | ||
@@ -166,6 +189,3 @@ )); | ||
} | ||
var childValue = child.props.value; | ||
if (typeof childValue !== 'string') { | ||
throw new Error('Option must set string value'); | ||
} | ||
var childValue = _this3.getValuePropValue(child); | ||
if (_this3.filterOption(inputValue, child)) { | ||
@@ -196,3 +216,3 @@ sel.push(React.createElement(MenuItem, _extends({ | ||
var notFindInputItem = sel.every(function (s) { | ||
return s.props.value !== inputValue; | ||
return _this3.getValuePropValue(s) !== inputValue; | ||
}); | ||
@@ -332,3 +352,3 @@ if (notFindInputItem) { | ||
var props = this.props; | ||
var selectedValue = item.props.value; | ||
var selectedValue = this.getValuePropValue(item); | ||
if (value.indexOf(selectedValue) !== -1) { | ||
@@ -354,3 +374,3 @@ return; | ||
this.setState({ | ||
inputValue: item.props[this.props.optionLabelProp] | ||
inputValue: this.getPropValue(item, this.props.optionLabelProp) | ||
}); | ||
@@ -363,3 +383,3 @@ } | ||
if (e.type === 'click') { | ||
this.removeSelected(item.props.value); | ||
this.removeSelected(this.getValuePropValue(item)); | ||
} | ||
@@ -428,2 +448,4 @@ this.setState({ | ||
value: function renderMenu(menuItems) { | ||
var _this6 = this; | ||
var props = this.props; | ||
@@ -438,3 +460,3 @@ var menuProps = {}; | ||
React.Children.forEach(menuItems, function (item) { | ||
var itemValue = item.props.value; | ||
var itemValue = _this6.getValuePropValue(item); | ||
var itemKey = item.key; | ||
@@ -468,3 +490,3 @@ if (value.indexOf(itemValue) !== -1 && itemKey) { | ||
value: function renderTopControlNode(input) { | ||
var _this6 = this; | ||
var _this7 = this; | ||
@@ -498,3 +520,3 @@ var value = this.state.value; | ||
selectedValueNodes = value.map(function (v) { | ||
var content = _this6.getLabelByValue(children, v) || v; | ||
var content = _this7.getLabelByValue(children, v) || v; | ||
var title = content; | ||
@@ -516,3 +538,3 @@ var maxTagTextLength = props.maxTagTextLength; | ||
React.createElement('span', { className: prefixCls + '-selection__choice__remove', | ||
onClick: _this6.removeSelected.bind(_this6, v) }) | ||
onClick: _this7.removeSelected.bind(_this7, v) }) | ||
); | ||
@@ -519,0 +541,0 @@ }); |
{ | ||
"name": "rc-select", | ||
"version": "4.2.0", | ||
"version": "4.2.1", | ||
"description": "select ui component for react", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -216,6 +216,12 @@ # rc-select | ||
<tr> | ||
<td>key</td> | ||
<td>String</td> | ||
<td></td> | ||
<td>if react want you to set key, then key is same as value, you can omit value.</td> | ||
</tr> | ||
<tr> | ||
<td>value</td> | ||
<td>String</td> | ||
<td></td> | ||
<td>search by this attribute</td> | ||
<td>default filter by this attribute. if react want you to set key, then key is same as value, you can omit value.</td> | ||
</tr> | ||
@@ -222,0 +228,0 @@ </tbody> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44234
1059
282