react-select-search
Advanced tools
Comparing version 1.1.5 to 1.1.6
@@ -77,2 +77,25 @@ "use strict"; | ||
var updateValue = function updateValue(newValue, optionsList) { | ||
if (newValue === void 0) { | ||
newValue = undefined; | ||
} | ||
if (optionsList === void 0) { | ||
optionsList = flatDefaultOptions; | ||
} | ||
if (newValue === undefined && value) { | ||
return; | ||
} | ||
var option = (0, _getOption["default"])(newValue || defaultValue, optionsList); | ||
if (!option && !allowEmpty) { | ||
var _optionsList = optionsList; | ||
option = _optionsList[0]; | ||
} | ||
setValue(option); | ||
}; | ||
var onBlur = function onBlur() { | ||
@@ -190,4 +213,4 @@ setFocus(false); | ||
(0, _react.useEffect)(function () { | ||
setValue((0, _getOption["default"])(defaultValue, flatDefaultOptions)); | ||
}, [defaultValue, flatDefaultOptions]); | ||
return updateValue(defaultValue); | ||
}, [defaultValue]); | ||
(0, _react.useEffect)(function () { | ||
@@ -197,8 +220,4 @@ var flatOptions = (0, _flattenOptions["default"])(defaultOptions); | ||
setFlatDefaultOptions(flatOptions); | ||
updateValue(undefined, flatOptions); | ||
}, [defaultOptions]); | ||
(0, _react.useEffect)(function () { | ||
if (!value && flatDefaultOptions && !allowEmpty) { | ||
setValue(flatDefaultOptions[0]); | ||
} | ||
}, [flatDefaultOptions, value, allowEmpty]); | ||
return [{ | ||
@@ -205,0 +224,0 @@ value: value, |
@@ -31,2 +31,16 @@ import { useReducer, useEffect, useMemo, useState, useRef } from 'react'; | ||
const updateValue = (newValue = undefined, optionsList = flatDefaultOptions) => { | ||
if (newValue === undefined && value) { | ||
return; | ||
} | ||
let option = getOption(newValue || defaultValue, optionsList); | ||
if (!option && !allowEmpty) { | ||
[option] = optionsList; | ||
} | ||
setValue(option); | ||
}; | ||
const onBlur = () => { | ||
@@ -134,15 +148,9 @@ setFocus(false); | ||
}; | ||
useEffect(() => updateValue(defaultValue), [defaultValue]); | ||
useEffect(() => { | ||
setValue(getOption(defaultValue, flatDefaultOptions)); | ||
}, [defaultValue, flatDefaultOptions]); | ||
useEffect(() => { | ||
const flatOptions = FlattenOptions(defaultOptions); | ||
setOptions(flatOptions); | ||
setFlatDefaultOptions(flatOptions); | ||
updateValue(undefined, flatOptions); | ||
}, [defaultOptions]); | ||
useEffect(() => { | ||
if (!value && flatDefaultOptions && !allowEmpty) { | ||
setValue(flatDefaultOptions[0]); | ||
} | ||
}, [flatDefaultOptions, value, allowEmpty]); | ||
return [{ | ||
@@ -149,0 +157,0 @@ value, |
{ | ||
"name": "react-select-search", | ||
"version": "1.1.5", | ||
"version": "1.1.6", | ||
"description": "Lightweight select component for React", | ||
@@ -5,0 +5,0 @@ "main": "dist/esm/index.js", |
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
68003
1354