karsten-design-system 1.1.77 → 1.1.79
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 +16 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4160,43 +4160,50 @@ function Select(props) {
|
|
|
4160
4160
|
const [highlightedIndex, setHighlightedIndex] = useState(-1);
|
|
4161
4161
|
const containerRef = useRef(null);
|
|
4162
4162
|
const inputRef = useRef(null);
|
|
4163
|
+
const hasOnInputChange = props?.onInputChange !== undefined;
|
|
4163
4164
|
const normalize = (str) => str
|
|
4164
4165
|
.normalize('NFD')
|
|
4165
4166
|
.replace(/[\u0300-\u036f]/g, '')
|
|
4166
4167
|
.toLowerCase();
|
|
4167
|
-
// const filteredOptions = options.filter((option) =>
|
|
4168
|
-
// normalize(option.label).includes(normalize(searchText))
|
|
4169
|
-
// )
|
|
4170
4168
|
const filteredOptions = (() => {
|
|
4171
|
-
if (
|
|
4172
|
-
return options
|
|
4169
|
+
if (hasOnInputChange && searchText.length > 0) {
|
|
4170
|
+
return options;
|
|
4173
4171
|
}
|
|
4174
|
-
if (isOpen && props.value) {
|
|
4172
|
+
if (hasOnInputChange && isOpen && !searchText.length && props.value) {
|
|
4175
4173
|
return [props.value];
|
|
4176
4174
|
}
|
|
4175
|
+
if (!hasOnInputChange) {
|
|
4176
|
+
return options.filter((option) => normalize(option.label).includes(normalize(searchText)));
|
|
4177
|
+
}
|
|
4177
4178
|
return [];
|
|
4178
4179
|
})();
|
|
4179
4180
|
const toggleDropdown = () => {
|
|
4180
4181
|
if (!disabled && !isLoading) {
|
|
4181
4182
|
const newState = !isOpen;
|
|
4182
4183
|
setIsOpen(newState);
|
|
4183
|
-
setSearchText('');
|
|
4184
4184
|
setHighlightedIndex(-1);
|
|
4185
4185
|
if (newState) {
|
|
4186
4186
|
setTimeout(() => {
|
|
4187
4187
|
inputRef.current?.focus();
|
|
4188
4188
|
}, 0);
|
|
4189
|
+
setSearchText('');
|
|
4190
|
+
}
|
|
4191
|
+
else {
|
|
4192
|
+
setSearchText(props.value?.label ?? '');
|
|
4189
4193
|
}
|
|
4190
4194
|
}
|
|
4191
4195
|
};
|
|
4192
4196
|
const handleSelect = (option) => {
|
|
4193
4197
|
if (props.value?.value === option.value) {
|
|
4194
4198
|
props.onChange(null);
|
|
4199
|
+
setSearchText('');
|
|
4195
4200
|
}
|
|
4196
4201
|
else {
|
|
4197
4202
|
props.onChange(option);
|
|
4203
|
+
if (!hasOnInputChange) {
|
|
4204
|
+
setSearchText(option.label);
|
|
4205
|
+
}
|
|
4198
4206
|
}
|
|
4199
|
-
setSearchText('');
|
|
4200
4207
|
setIsOpen(false);
|
|
4201
4208
|
setHighlightedIndex(-1);
|
|
4202
4209
|
};
|
|
@@ -4212,7 +4219,7 @@ function Select(props) {
|
|
|
4212
4219
|
if (containerRef.current &&
|
|
4213
4220
|
!containerRef.current.contains(event.target)) {
|
|
4214
4221
|
setIsOpen(false);
|
|
4215
|
-
setSearchText('');
|
|
4222
|
+
setSearchText(props.value?.label ?? '');
|
|
4216
4223
|
setHighlightedIndex(-1);
|
|
4217
4224
|
}
|
|
4218
4225
|
};
|