@sustaina/shared-ui 1.36.0 → 1.36.1

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.mjs CHANGED
@@ -3194,6 +3194,7 @@ var LookupSelect = ({
3194
3194
  }) => {
3195
3195
  const [inputValue, setInputValue] = useState("");
3196
3196
  const inputRef = useRef(null);
3197
+ const [inputFocused, setInputFocused] = useState(false);
3197
3198
  const [suggestions, setSuggestions] = useState([]);
3198
3199
  const [optionLabels, setOptionLabels] = useState({});
3199
3200
  const [loading, setLoading] = useState(false);
@@ -3244,8 +3245,6 @@ var LookupSelect = ({
3244
3245
  onChange([trimmed]);
3245
3246
  }
3246
3247
  setInputValue("");
3247
- setSuggestions([]);
3248
- setIsDropdownOpen(false);
3249
3248
  },
3250
3249
  [value, onChange, maxTags, multiple]
3251
3250
  );
@@ -3254,12 +3253,15 @@ var LookupSelect = ({
3254
3253
  if (index < 0) return;
3255
3254
  const newTags = value.filter((_, i) => i !== index);
3256
3255
  onChange(newTags);
3256
+ setIsDropdownOpen(false);
3257
+ setInputFocused(false);
3257
3258
  },
3258
3259
  [value, onChange]
3259
3260
  );
3260
3261
  const handleClear = useCallback(() => {
3261
3262
  setInputValue("");
3262
3263
  setSuggestions([]);
3264
+ setInputFocused(false);
3263
3265
  setIsDropdownOpen(false);
3264
3266
  setFetchError(null);
3265
3267
  if (onClear) onClear();
@@ -3275,7 +3277,10 @@ var LookupSelect = ({
3275
3277
  }, 100);
3276
3278
  } else {
3277
3279
  inputRef.current?.blur();
3280
+ setInputFocused(false);
3281
+ setIsDropdownOpen(false);
3278
3282
  }
3283
+ inputRef.current.value = "";
3279
3284
  },
3280
3285
  [addTag, multiple, upsertOptionLabels]
3281
3286
  );
@@ -3318,18 +3323,11 @@ var LookupSelect = ({
3318
3323
  });
3319
3324
  }, [dropdownPortalElement]);
3320
3325
  useEffect(() => {
3321
- if (!fetchSuggestions) return;
3326
+ if (!fetchSuggestions || !inputFocused) return;
3322
3327
  if (fetchDelayRef.current) {
3323
3328
  clearTimeout(fetchDelayRef.current);
3324
3329
  }
3325
3330
  const query = inputValue.trim();
3326
- if (!query) {
3327
- setSuggestions([]);
3328
- setIsDropdownOpen(false);
3329
- setLoading(false);
3330
- setFetchError(null);
3331
- return;
3332
- }
3333
3331
  setLoading(true);
3334
3332
  setFetchError(null);
3335
3333
  setIsDropdownOpen(true);
@@ -3357,7 +3355,7 @@ var LookupSelect = ({
3357
3355
  clearTimeout(fetchDelayRef.current);
3358
3356
  }
3359
3357
  };
3360
- }, [inputValue, fetchSuggestions, suggestionDebounce, upsertOptionLabels]);
3358
+ }, [inputValue, fetchSuggestions, suggestionDebounce, upsertOptionLabels, inputFocused]);
3361
3359
  useEffect(() => {
3362
3360
  if (!fetchSuggestions) return;
3363
3361
  if (value.length === 0) return;
@@ -3374,6 +3372,7 @@ var LookupSelect = ({
3374
3372
  if (containerRef.current?.contains(target)) return;
3375
3373
  if (dropdownContentRef.current?.contains(target)) return;
3376
3374
  setIsDropdownOpen(false);
3375
+ setInputFocused(false);
3377
3376
  };
3378
3377
  document.addEventListener("mousedown", handleDocumentClick);
3379
3378
  return () => {
@@ -3395,7 +3394,7 @@ var LookupSelect = ({
3395
3394
  window.removeEventListener("resize", handleReposition);
3396
3395
  window.removeEventListener("scroll", handleReposition, true);
3397
3396
  };
3398
- }, [dropdownPortalElement, isDropdownOpen, updateDropdownPosition]);
3397
+ }, [dropdownPortalElement, isDropdownOpen, updateDropdownPosition, value]);
3399
3398
  useEffect(() => {
3400
3399
  if (suggestions.length === 0) {
3401
3400
  setActiveSuggestionIndex(-1);
@@ -3450,7 +3449,7 @@ var LookupSelect = ({
3450
3449
  return /* @__PURE__ */ jsxs(
3451
3450
  "span",
3452
3451
  {
3453
- className: "flex items-center gap-1 rounded-lg border border-[#f0f0f0] bg-[#f9f9f9] px-2 py-1 my-1 text-sm text-inherit max-w-full wrap-break-word",
3452
+ className: "flex items-center gap-1 rounded-lg border border-sus-secondary-gray-3 bg-sus-secondary-gray-2 px-2 py-1 my-1 text-sm text-inherit max-w-full wrap-break-word",
3454
3453
  children: [
3455
3454
  /* @__PURE__ */ jsx("span", { className: "whitespace-pre-wrap break-all", children: label }),
3456
3455
  /* @__PURE__ */ jsx(
@@ -3478,9 +3477,7 @@ var LookupSelect = ({
3478
3477
  onChange: (e) => setInputValue(e.target.value),
3479
3478
  onKeyDown: handleKeyDown,
3480
3479
  onFocus: () => {
3481
- if (suggestions.length > 0 && !fetchError) {
3482
- setIsDropdownOpen(true);
3483
- }
3480
+ setInputFocused(true);
3484
3481
  },
3485
3482
  hidden: !multiple && selectedLabel !== void 0,
3486
3483
  placeholder: value.length === 0 && resolvedPlaceholder || "",