karsten-design-system 1.1.81 → 1.1.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +21 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4165,29 +4165,32 @@ function Select(props) {
|
|
|
4165
4165
|
.normalize('NFD')
|
|
4166
4166
|
.replace(/[\u0300-\u036f]/g, '')
|
|
4167
4167
|
.toLowerCase();
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
// return []
|
|
4178
|
-
// })()
|
|
4168
|
+
const ensureValueInOptions = (optionsList, currentValue) => {
|
|
4169
|
+
if (!currentValue)
|
|
4170
|
+
return optionsList;
|
|
4171
|
+
const allOptions = [...optionsList];
|
|
4172
|
+
if (!allOptions.find(opt => opt.value === currentValue.value)) {
|
|
4173
|
+
allOptions.unshift(currentValue);
|
|
4174
|
+
}
|
|
4175
|
+
return allOptions;
|
|
4176
|
+
};
|
|
4179
4177
|
const filteredOptions = (() => {
|
|
4180
4178
|
const hasSearch = searchText.length > 0;
|
|
4179
|
+
const allOptions = ensureValueInOptions(options, props.value);
|
|
4181
4180
|
if (hasOnInputChange) {
|
|
4182
4181
|
if (isOpen) {
|
|
4183
4182
|
if (hasSearch) {
|
|
4184
|
-
|
|
4183
|
+
const filtered = allOptions.filter((option) => normalize(option.label).includes(normalize(searchText)));
|
|
4184
|
+
if (props.value && !filtered.find(opt => opt.value === props.value?.value)) {
|
|
4185
|
+
filtered.unshift(props.value);
|
|
4186
|
+
}
|
|
4187
|
+
return filtered;
|
|
4185
4188
|
}
|
|
4186
|
-
return
|
|
4189
|
+
return allOptions;
|
|
4187
4190
|
}
|
|
4188
4191
|
return props.value ? [props.value] : [];
|
|
4189
4192
|
}
|
|
4190
|
-
return
|
|
4193
|
+
return allOptions.filter((option) => normalize(option.label).includes(normalize(searchText)));
|
|
4191
4194
|
})();
|
|
4192
4195
|
const toggleDropdown = () => {
|
|
4193
4196
|
if (!disabled && !isLoading) {
|
|
@@ -4200,11 +4203,13 @@ function Select(props) {
|
|
|
4200
4203
|
}, 0);
|
|
4201
4204
|
}
|
|
4202
4205
|
else {
|
|
4203
|
-
setSearchText(
|
|
4206
|
+
setSearchText('');
|
|
4204
4207
|
}
|
|
4205
4208
|
}
|
|
4206
4209
|
};
|
|
4207
4210
|
const handleSelect = (option) => {
|
|
4211
|
+
if (!option)
|
|
4212
|
+
return;
|
|
4208
4213
|
if (props.value?.value === option.value) {
|
|
4209
4214
|
props.onChange(null);
|
|
4210
4215
|
setSearchText('');
|
|
@@ -4230,7 +4235,7 @@ function Select(props) {
|
|
|
4230
4235
|
if (containerRef.current &&
|
|
4231
4236
|
!containerRef.current.contains(event.target)) {
|
|
4232
4237
|
setIsOpen(false);
|
|
4233
|
-
setSearchText(
|
|
4238
|
+
setSearchText('');
|
|
4234
4239
|
setHighlightedIndex(-1);
|
|
4235
4240
|
}
|
|
4236
4241
|
};
|