karsten-design-system 1.1.82 → 1.1.83

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 CHANGED
@@ -4169,29 +4169,40 @@ function Select(props) {
4169
4169
  if (!currentValue)
4170
4170
  return optionsList;
4171
4171
  const allOptions = [...optionsList];
4172
- if (!allOptions.find(opt => opt.value === currentValue.value)) {
4172
+ if (!allOptions.find((opt) => opt.value === currentValue.value)) {
4173
4173
  allOptions.unshift(currentValue);
4174
4174
  }
4175
4175
  return allOptions;
4176
4176
  };
4177
4177
  const filteredOptions = (() => {
4178
- const hasSearch = searchText.length > 0;
4179
4178
  const allOptions = ensureValueInOptions(options, props.value);
4179
+ const hasSearch = searchText.length > 0;
4180
4180
  if (hasOnInputChange) {
4181
4181
  if (isOpen) {
4182
4182
  if (hasSearch) {
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;
4183
+ return allOptions;
4188
4184
  }
4189
4185
  return allOptions;
4190
4186
  }
4191
- return props.value ? [props.value] : [];
4187
+ return allOptions;
4192
4188
  }
4193
4189
  return allOptions.filter((option) => normalize(option.label).includes(normalize(searchText)));
4194
4190
  })();
4191
+ const handleSelect = (option) => {
4192
+ if (!option)
4193
+ return;
4194
+ if (props.value?.value === option.value) {
4195
+ props.onChange(null);
4196
+ setSearchText('');
4197
+ }
4198
+ else {
4199
+ props.onChange(option);
4200
+ if (!hasOnInputChange) {
4201
+ setSearchText(option.label);
4202
+ }
4203
+ }
4204
+ handleClose();
4205
+ };
4195
4206
  const toggleDropdown = () => {
4196
4207
  if (!disabled && !isLoading) {
4197
4208
  const newState = !isOpen;
@@ -4203,25 +4214,13 @@ function Select(props) {
4203
4214
  }, 0);
4204
4215
  }
4205
4216
  else {
4206
- setSearchText('');
4217
+ handleClose();
4207
4218
  }
4208
4219
  }
4209
4220
  };
4210
- const handleSelect = (option) => {
4211
- if (!option)
4212
- return;
4213
- if (props.value?.value === option.value) {
4214
- props.onChange(null);
4215
- setSearchText('');
4216
- }
4217
- else {
4218
- props.onChange(option);
4219
- if (!hasOnInputChange) {
4220
- setSearchText(option.label);
4221
- }
4222
- }
4221
+ const handleClose = () => {
4223
4222
  setIsOpen(false);
4224
- setHighlightedIndex(-1);
4223
+ setSearchText('');
4225
4224
  };
4226
4225
  const hasError = !!error && !disabled;
4227
4226
  const isInputDisabled = disabled || isLoading;
@@ -4234,9 +4233,7 @@ function Select(props) {
4234
4233
  const handleClickOutside = (event) => {
4235
4234
  if (containerRef.current &&
4236
4235
  !containerRef.current.contains(event.target)) {
4237
- setIsOpen(false);
4238
- setSearchText('');
4239
- setHighlightedIndex(-1);
4236
+ handleClose();
4240
4237
  }
4241
4238
  };
4242
4239
  document.addEventListener('mousedown', handleClickOutside);
@@ -4249,10 +4246,14 @@ function Select(props) {
4249
4246
  : isOpen
4250
4247
  ? searchText
4251
4248
  : (props.value?.label ?? ''), onClick: toggleDropdown, onChange: (e) => {
4252
- if (isOpen) {
4253
- setSearchText(e.target.value);
4254
- setHighlightedIndex(0);
4255
- props.onInputChange?.(e.target.value);
4249
+ const inputValue = e.target.value;
4250
+ setSearchText(inputValue);
4251
+ setHighlightedIndex(0);
4252
+ if (hasOnInputChange) {
4253
+ props.onInputChange?.(inputValue);
4254
+ }
4255
+ if (!isOpen) {
4256
+ setIsOpen(true);
4256
4257
  }
4257
4258
  }, onKeyDown: (e) => {
4258
4259
  if (!isOpen)
@@ -4274,9 +4275,7 @@ function Select(props) {
4274
4275
  }
4275
4276
  if (e.key === 'Escape') {
4276
4277
  e.preventDefault();
4277
- setIsOpen(false);
4278
- setSearchText('');
4279
- setHighlightedIndex(-1);
4278
+ handleClose();
4280
4279
  }
4281
4280
  }, className: clsx('focus:shadow-none text-base w-100 font-roboto border !p-2 rounded-md', hasError
4282
4281
  ? 'border-redError placeholder:text-redError'