@seedgrid/fe-components 2026.4.17 → 2026.4.18
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/inputs/SgAutocomplete.js +42 -9
- package/dist/sandbox.cjs +44 -44
- package/package.json +1 -1
|
@@ -26,6 +26,7 @@ function SgAutocompleteBase(props) {
|
|
|
26
26
|
const loadingText = loadingTextProp ?? t(i18n, "components.autocomplete.loading");
|
|
27
27
|
const effectiveGrouped = grouped ?? groupped ?? false;
|
|
28
28
|
const [inputValue, setInputValue] = React.useState(value ?? "");
|
|
29
|
+
const [internalError, setInternalError] = React.useState(null);
|
|
29
30
|
const [items, setItems] = React.useState([]);
|
|
30
31
|
const [loading, setLoading] = React.useState(false);
|
|
31
32
|
const [open, setOpen] = React.useState(false);
|
|
@@ -53,11 +54,14 @@ function SgAutocompleteBase(props) {
|
|
|
53
54
|
React.useEffect(() => {
|
|
54
55
|
if (value === undefined)
|
|
55
56
|
return;
|
|
56
|
-
setLastSelected(value);
|
|
57
57
|
// Never clobber what the user is actively typing.
|
|
58
58
|
if (isFocusedRef.current)
|
|
59
59
|
return;
|
|
60
|
+
setLastSelected(value);
|
|
60
61
|
setInputValue(value);
|
|
62
|
+
if (!value) {
|
|
63
|
+
setInternalError(null);
|
|
64
|
+
}
|
|
61
65
|
}, [value]);
|
|
62
66
|
React.useEffect(() => {
|
|
63
67
|
if (!value) {
|
|
@@ -138,6 +142,7 @@ function SgAutocompleteBase(props) {
|
|
|
138
142
|
const selection = formatSelection ? formatSelection(item) : item.label;
|
|
139
143
|
setSelectedItem(item);
|
|
140
144
|
setInputValue(selection);
|
|
145
|
+
setInternalError(null);
|
|
141
146
|
onChange?.(selection);
|
|
142
147
|
setLastSelected(selection);
|
|
143
148
|
onSelect?.(item);
|
|
@@ -152,8 +157,14 @@ function SgAutocompleteBase(props) {
|
|
|
152
157
|
if (selectedItem && next !== (formatSelection ? formatSelection(selectedItem) : selectedItem.label)) {
|
|
153
158
|
setSelectedItem(null);
|
|
154
159
|
}
|
|
160
|
+
setInternalError(null);
|
|
155
161
|
setInputValue(next);
|
|
156
|
-
|
|
162
|
+
if (allowCustomValue || next.length === 0) {
|
|
163
|
+
onChange?.(next);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
onChange?.("");
|
|
167
|
+
}
|
|
157
168
|
if (next.length === 0) {
|
|
158
169
|
setItems([]);
|
|
159
170
|
setOpen(false);
|
|
@@ -178,9 +189,20 @@ function SgAutocompleteBase(props) {
|
|
|
178
189
|
return;
|
|
179
190
|
}
|
|
180
191
|
isFocusedRef.current = false;
|
|
181
|
-
if (!allowCustomValue &&
|
|
182
|
-
|
|
183
|
-
|
|
192
|
+
if (!allowCustomValue && inputValue !== lastSelected) {
|
|
193
|
+
if (lastSelected) {
|
|
194
|
+
setInputValue(lastSelected);
|
|
195
|
+
setInternalError(null);
|
|
196
|
+
onChange?.(lastSelected);
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
setInputValue("");
|
|
200
|
+
setSelectedItem(null);
|
|
201
|
+
setInternalError(props.required
|
|
202
|
+
? props.requiredMessage ?? t(i18n, "components.inputs.required")
|
|
203
|
+
: null);
|
|
204
|
+
onChange?.("");
|
|
205
|
+
}
|
|
184
206
|
}
|
|
185
207
|
setOpen(false);
|
|
186
208
|
onOpenChange?.(false);
|
|
@@ -293,9 +315,20 @@ function SgAutocompleteBase(props) {
|
|
|
293
315
|
return;
|
|
294
316
|
if (dropdownRef.current?.contains(event.target))
|
|
295
317
|
return;
|
|
296
|
-
if (!allowCustomValue &&
|
|
297
|
-
|
|
298
|
-
|
|
318
|
+
if (!allowCustomValue && inputValue !== lastSelected) {
|
|
319
|
+
if (lastSelected) {
|
|
320
|
+
setInputValue(lastSelected);
|
|
321
|
+
setInternalError(null);
|
|
322
|
+
onChange?.(lastSelected);
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
setInputValue("");
|
|
326
|
+
setSelectedItem(null);
|
|
327
|
+
setInternalError(props.required
|
|
328
|
+
? props.requiredMessage ?? t(i18n, "components.inputs.required")
|
|
329
|
+
: null);
|
|
330
|
+
onChange?.("");
|
|
331
|
+
}
|
|
299
332
|
}
|
|
300
333
|
setOpen(false);
|
|
301
334
|
onOpenChange?.(false);
|
|
@@ -317,7 +350,7 @@ function SgAutocompleteBase(props) {
|
|
|
317
350
|
window.removeEventListener("scroll", handleLayoutChange, true);
|
|
318
351
|
};
|
|
319
352
|
}, [open, syncDropdownPosition]);
|
|
320
|
-
return (_jsxs("div", { className: "relative", ref: wrapperRef, children: [_jsx(SgInputText, { ...rest, enabled: enabled, readOnly: readOnly, borderRadius: borderRadius, iconButtons: mergedIconButtons, inputProps: {
|
|
353
|
+
return (_jsxs("div", { className: "relative", ref: wrapperRef, children: [_jsx(SgInputText, { ...rest, error: resolveFieldError(rest.error, internalError ?? undefined), enabled: enabled, readOnly: readOnly, borderRadius: borderRadius, iconButtons: mergedIconButtons, inputProps: {
|
|
321
354
|
...inputProps,
|
|
322
355
|
ref: inputRef,
|
|
323
356
|
autoComplete: "off",
|