fix: keep direct icon URLs visible (#6504)

This commit is contained in:
Thomas authored and GitHub committed 2026-08-01 23:28:18 +02:00
1 parent 49314533bf
commit 797bdd001f
2 files changed
+123 -8

No files matched your search

@@ -63,7 +63,7 @@ export const IconPicker = ({
const tCommon = useScopedI18n("common");
const [debouncedQuery] = useDebouncedValue(query, 100);
const searchText = (debouncedQuery !== (value ?? "") && debouncedQuery) || "";
const searchText = !isDirectIconUrl(debouncedQuery) && debouncedQuery !== (value ?? "") ? debouncedQuery : "";
const { data, isLoading, isError, refetch } = clientApi.icon.findIcons.useQuery(
{ searchText },
@@ -167,15 +167,12 @@ export const IconPicker = ({
onChange={(event) => {
const nextValue = event.currentTarget.value;
const trimmedValue = nextValue.trim();
if (/^https?:\/\/[^\s/]+(?:\/\S*)?$/i.test(trimmedValue)) {
startTransition(() => {
setValue(trimmedValue);
setQuery("");
combobox.closeDropdown();
});
setQuery(nextValue);
if (isDirectIconUrl(trimmedValue)) {
setValue(trimmedValue);
combobox.closeDropdown();
} else {
combobox.openDropdown();
setQuery(nextValue);
}
}}
onClick={() => combobox.openDropdown()}
@@ -230,3 +227,12 @@ const shouldShowPreview = (value: string | null | undefined): value is string =>
if (!value) return false;
return !localizationPathRegex.test(value);
};
const isDirectIconUrl = (value: string) => {
try {
const url = new URL(value.trim());
return (url.protocol === "http:" || url.protocol === "https:") && Boolean(url.hostname);
} catch {
return false;
}
};