react-polymorph
Advanced tools
Comparing version 0.9.8-rc.11 to 0.9.8-rc.12
@@ -9,2 +9,6 @@ Changelog | ||
### Features | ||
- Enabled pasting of multiple words into Autocomplete ([PR 163](https://github.com/input-output-hk/react-polymorph/pull/163)) | ||
### Fixes | ||
@@ -11,0 +15,0 @@ |
@@ -14,3 +14,3 @@ "use strict"; | ||
var _concat2 = _interopRequireDefault(require("lodash/concat")); | ||
var _isString2 = _interopRequireDefault(require("lodash/isString")); | ||
@@ -45,2 +45,10 @@ var _react = _interopRequireWildcard(require("react")); | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -144,4 +152,6 @@ | ||
_this.setState({ | ||
isOpen: !_this.state.isOpen | ||
_this.setState(function (prevState) { | ||
return { | ||
isOpen: !prevState.isOpen | ||
}; | ||
}); | ||
@@ -151,4 +161,6 @@ }); | ||
_defineProperty(_assertThisInitialized(_this), "toggleMouseLocation", function () { | ||
return _this.setState({ | ||
mouseIsOverOptions: !_this.state.mouseIsOverOptions | ||
return _this.setState(function (prevState) { | ||
return { | ||
mouseIsOverOptions: !prevState.mouseIsOverOptions | ||
}; | ||
}); | ||
@@ -185,2 +197,8 @@ }); | ||
_this._setInputValue(event.target.value); | ||
var multipleValues = event.target.value.split(' '); | ||
if (multipleValues && multipleValues.length > 1) { | ||
_this.updateSelectedOptions(event, multipleValues); | ||
} | ||
}); | ||
@@ -203,21 +221,44 @@ | ||
var areFilteredOptionsAvailable = filteredOptions && filteredOptions.length > 0; | ||
var skipValueSelection = false; | ||
if (!maxSelections || canMoreOptionsBeSelected && areFilteredOptionsAvailable) { | ||
if (!selectedOption) return; | ||
var option = selectedOption.trim(); | ||
var optionCanBeSelected = selectedOptions.indexOf(option) < 0 && !multipleSameSelections || multipleSameSelections; | ||
if (!selectedOption || !selectedOption.length) return; | ||
var option = (0, _isString2["default"])(selectedOption) ? selectedOption.trim() : selectedOption; | ||
if (option && optionCanBeSelected && isOpen) { | ||
var newSelectedOptions = (0, _concat2["default"])(selectedOptions, option); | ||
var newSelectedOptions = _toConsumableArray(selectedOptions); | ||
_this.selectionChanged(newSelectedOptions, event); | ||
if (option && Array.isArray(option)) { | ||
option.forEach(function (item) { | ||
var optionCanBeSelected = multipleSameSelections && filteredOptions.includes(item) || filteredOptions.includes(item) && !selectedOptions.includes(item) && !newSelectedOptions.includes(item); | ||
_this.setState({ | ||
selectedOptions: newSelectedOptions, | ||
isOpen: false | ||
if (!optionCanBeSelected && !skipValueSelection) { | ||
_this._setInputValue(item, true); | ||
skipValueSelection = true; | ||
return; | ||
} | ||
if (item && optionCanBeSelected && isOpen && !skipValueSelection) { | ||
newSelectedOptions.push(item); | ||
} | ||
}); | ||
} else { | ||
var optionCanBeSelected = multipleSameSelections || !selectedOptions.includes(option); | ||
if (option && optionCanBeSelected && isOpen) { | ||
newSelectedOptions.push(option); | ||
} | ||
} | ||
_this.selectionChanged(newSelectedOptions, event); | ||
_this.setState({ | ||
selectedOptions: newSelectedOptions, | ||
isOpen: false | ||
}); | ||
} | ||
_this._setInputValue(''); | ||
if (!skipValueSelection) { | ||
_this._setInputValue(''); | ||
} | ||
}); | ||
@@ -302,12 +343,33 @@ | ||
_defineProperty(_assertThisInitialized(_this), "_setInputValue", function (value) { | ||
var filteredValue = _this._filterInvalidChars(value); | ||
_defineProperty(_assertThisInitialized(_this), "_setInputValue", function (value, shouldFocus) { | ||
var multipleValues = value.split(' '); | ||
var filteredOptions = _this._filterOptions(filteredValue); | ||
if (multipleValues && multipleValues.length > 1) { | ||
var filteredOptions = []; | ||
multipleValues.forEach(function (itemValue) { | ||
var filteredValue = _this._filterInvalidChars(itemValue); | ||
_this.setState({ | ||
isOpen: true, | ||
inputValue: filteredValue, | ||
filteredOptions: filteredOptions | ||
}); | ||
filteredOptions.push(_this._filterOptions(filteredValue)); | ||
}); | ||
_this.setState({ | ||
isOpen: true, | ||
inputValue: '', | ||
filteredOptions: filteredOptions | ||
}); | ||
} else { | ||
var filteredValue = _this._filterInvalidChars(value); | ||
var _filteredOptions = _this._filterOptions(filteredValue); | ||
_this.setState({ | ||
isOpen: true, | ||
inputValue: filteredValue, | ||
filteredOptions: _filteredOptions | ||
}); | ||
setTimeout(function () { | ||
if (shouldFocus) _this.focus(); | ||
}, 0); | ||
} | ||
}); | ||
@@ -415,3 +477,3 @@ | ||
error: null, | ||
invalidCharsRegex: /[^a-zA-Z0-9]/g, | ||
invalidCharsRegex: /[^a-zA-Z0-9\s]/g, | ||
// only allow letters and numbers by default | ||
@@ -418,0 +480,0 @@ isOpeningUpward: false, |
{ | ||
"name": "react-polymorph", | ||
"description": "React components with highly customizable logic, markup and styles.", | ||
"version": "0.9.8-rc.11", | ||
"version": "0.9.8-rc.12", | ||
"scripts": { | ||
@@ -6,0 +6,0 @@ "build": "cross-env yarn clean && yarn sass && yarn js", |
Sorry, the diff of this file is not supported yet
1273870
7552