;
- onChange(event);
- }
+ emitChange("");
};
+ const pickItem = (itemValue: string) => {
+ emitChange(itemValue);
+ setOpen(false);
+ setQuery("");
+ triggerRef.current?.focus();
+ };
+
+ const selectSharedClasses = cn(
+ "w-full appearance-none rounded-xl border border-stroke/70 bg-white/90 px-5.5 py-3 shadow-[0_1px_2px_rgba(16,24,40,0.04),0_8px_20px_rgba(16,24,40,0.04)] outline-none backdrop-blur-[1px] transition-all duration-200 focus:border-primary/70 focus:bg-white focus:shadow-[0_0_0_2px_rgba(59,130,246,0.14),0_10px_24px_rgba(59,130,246,0.08)] active:border-primary/70 dark:border-dark-3/80 dark:bg-dark-2/85 dark:focus:border-primary/80 dark:focus:shadow-[0_0_0_2px_rgba(59,130,246,0.2),0_10px_24px_rgba(15,23,42,0.45)] [&>option]:text-dark-5 dark:[&>option]:text-dark-6",
+ isOptionSelected && "text-dark dark:text-white",
+ disabled &&
+ "cursor-not-allowed opacity-60 hover:border-stroke/70 dark:hover:border-dark-3/80",
+ error &&
+ "border-red/80 focus:border-red focus:shadow-[0_0_0_2px_rgba(239,68,68,0.16),0_10px_24px_rgba(239,68,68,0.1)] dark:border-red/80 dark:focus:shadow-[0_0_0_2px_rgba(239,68,68,0.24),0_10px_24px_rgba(127,29,29,0.45)]",
+ prefixIcon && "pl-11.5",
+ clearable && value && "pr-20",
+ );
+
+ const dropdown =
+ searchable &&
+ mounted &&
+ open &&
+ panelRect &&
+ typeof document !== "undefined" &&
+ createPortal(
+ {
+ const w = Math.max(panelRect.width, 200);
+ if (typeof window === "undefined") return panelRect.left;
+ return Math.min(
+ Math.max(8, panelRect.left),
+ window.innerWidth - w - 8,
+ );
+ })(),
+ width: Math.max(panelRect.width, 200),
+ }}
+ >
+
+
+ setQuery(e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === "Escape") {
+ e.stopPropagation();
+ setOpen(false);
+ setQuery("");
+ triggerRef.current?.focus();
+ }
+ }}
+ placeholder={searchPlaceholder}
+ data-cy={dataCy ? `${dataCy}-search` : undefined}
+ autoComplete="off"
+ spellCheck={false}
+ className="w-full rounded-lg border border-stroke/60 bg-white/95 px-3 py-2 text-sm text-dark outline-none ring-primary/20 placeholder:text-dark-5 focus:border-primary/60 focus:ring-2 dark:border-white/10 dark:bg-dark-3/90 dark:text-white dark:placeholder:text-dark-6"
+ />
+
+
+ {isSearchLoading ? (
+ -
+
+ Searching…
+
+ ) : isSearchError ? (
+ -
+ Could not load options. Try again.
+
+ ) : listItems.length === 0 ? (
+ -
+ No matches.
+
+ ) : (
+ listItems.map((item) => {
+ const v = String(item.value);
+ const isActive = v === String(value);
+ return (
+ -
+
+
+ );
+ })
+ )}
+
+
,
+ document.body,
+ );
+
+ if (searchable) {
+ return (
+
+
+
+
+
+
+ {prefixIcon && (
+
+ {prefixIcon}
+
+ )}
+
+
+
+ {clearable && value && (
+
+ )}
+
+
+
+
+ {dropdown}
+
+ {error && (
+
+ {error.message as string}
+
+ )}
+
+ );
+ }
+
return (