infinity-ui-elements 1.8.24 → 1.8.26

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
@@ -3218,7 +3218,7 @@ const TextField = React__namespace.forwardRef(({ label, helperText, errorText, s
3218
3218
  TextField.displayName = "TextField";
3219
3219
 
3220
3220
  const defaultFilter = (item, query) => {
3221
- const searchQuery = query.toLowerCase();
3221
+ const searchQuery = query?.toLowerCase();
3222
3222
  return (item.label?.toLowerCase()?.includes(searchQuery) ||
3223
3223
  (item.description?.toLowerCase()?.includes(searchQuery) ?? false));
3224
3224
  };
@@ -3316,19 +3316,19 @@ const SearchableDropdown = React__namespace.forwardRef(({ className, items = [],
3316
3316
  onClick: () => {
3317
3317
  if (onAddNew) {
3318
3318
  onAddNew(searchValue);
3319
+ // Don't update search value here - let parent handle it via onAddNew
3320
+ setIsOpen(false);
3321
+ inputRef.current?.focus();
3319
3322
  }
3320
3323
  else {
3324
+ // When onAddNew is not provided, create a new item and select it
3321
3325
  const newItem = {
3322
3326
  value: searchValue,
3323
3327
  label: searchValue,
3324
3328
  };
3325
- onItemSelect?.(newItem);
3326
- if (controlledSearchValue === undefined) {
3327
- setUncontrolledSearchValue(searchValue);
3328
- }
3329
+ // Use handleItemSelect to ensure proper behavior
3330
+ handleItemSelect(newItem);
3329
3331
  }
3330
- setIsOpen(false);
3331
- inputRef.current?.focus();
3332
3332
  },
3333
3333
  };
3334
3334
  // If showAddNewIfDoesNotMatch is true, only show "Add New" when no items match
@@ -3405,11 +3405,23 @@ const SearchableDropdown = React__namespace.forwardRef(({ className, items = [],
3405
3405
  }
3406
3406
  };
3407
3407
  // Update items with onClick handlers that call handleItemSelect
3408
- // Only add onClick if it doesn't already exist (for Add New items)
3409
- const itemsWithHandlers = itemsWithAddNew.map((item) => ({
3410
- ...item,
3411
- onClick: item.onClick || (() => handleItemSelect(item)),
3412
- }));
3408
+ // Always wrap onClick to ensure search value is updated with label
3409
+ const itemsWithHandlers = itemsWithAddNew.map((item) => {
3410
+ // Check if this is the "Add New" item (its onClick already handles selection properly)
3411
+ const isAddNewItem = showAddNew && item.label?.startsWith("+ Add");
3412
+ return {
3413
+ ...item,
3414
+ onClick: () => {
3415
+ // Call the custom onClick if it exists (for Add New items, etc.)
3416
+ item.onClick?.();
3417
+ // Call handleItemSelect to update search value with label and close dropdown
3418
+ // Skip for "Add New" items since their onClick already handles everything
3419
+ if (!isAddNewItem) {
3420
+ handleItemSelect(item);
3421
+ }
3422
+ },
3423
+ };
3424
+ });
3413
3425
  const showDropdown = isOpen && searchValue.length >= minSearchLength;
3414
3426
  const dropdownMenu = showDropdown && (jsxRuntime.jsx("div", { ref: menuRef, style: {
3415
3427
  position: "absolute",