@multiplatform.one/forms 7.19.0 → 7.21.0
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/cjs/fields/Combobox/index.cjs +39 -28
- package/dist/cjs/fields/Combobox/index.native.js +54 -30
- package/dist/cjs/fields/Combobox/index.native.js.map +1 -1
- package/dist/cjs/fields/Switch/footprint.cjs +1 -1
- package/dist/cjs/fields/Switch/footprint.native.js +1 -1
- package/dist/esm/fields/Combobox/index.mjs +39 -28
- package/dist/esm/fields/Combobox/index.mjs.map +1 -1
- package/dist/esm/fields/Combobox/index.native.js +54 -30
- package/dist/esm/fields/Combobox/index.native.js.map +1 -1
- package/dist/esm/fields/Switch/footprint.mjs +1 -1
- package/dist/esm/fields/Switch/footprint.native.js +1 -1
- package/dist/jsx/fields/Combobox/index.mjs +39 -28
- package/dist/jsx/fields/Combobox/index.mjs.map +1 -1
- package/dist/jsx/fields/Combobox/index.native.js +54 -30
- package/dist/jsx/fields/Combobox/index.native.js.map +1 -1
- package/dist/jsx/fields/Switch/footprint.mjs +1 -1
- package/dist/jsx/fields/Switch/footprint.native.js +1 -1
- package/package.json +8 -8
- package/src/fields/Combobox/Combobox.spec.tsx +158 -0
- package/src/fields/Combobox/index.tsx +57 -28
- package/src/fields/Switch/Switch.footprint.native.spec.tsx +14 -5
- package/src/fields/Switch/footprint.ts +3 -3
- package/types/fields/Combobox/index.d.ts +5 -1
- package/types/fields/Combobox/index.d.ts.map +1 -1
|
@@ -337,19 +337,18 @@ function FloatingComboboxCore({
|
|
|
337
337
|
return !options.some(o => o.label.toLowerCase() === trimmed || o.value.toLowerCase() === trimmed);
|
|
338
338
|
}, [creatable, filter, options]);
|
|
339
339
|
const handleCreate = (0, import_react.useCallback)(() => {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
setOpen(false);
|
|
349
|
-
}
|
|
340
|
+
const typed = filter.trim();
|
|
341
|
+
if (!onCreate || !typed) return;
|
|
342
|
+
const newOption = onCreate(typed);
|
|
343
|
+
if (newOption && multiple) {
|
|
344
|
+
const current = Array.isArray(value) ? value : value ? [value] : [];
|
|
345
|
+
if (!current.includes(newOption.value)) onValueChange?.([...current, newOption.value]);
|
|
346
|
+
} else if (newOption) {
|
|
347
|
+
onValueChange?.(newOption.value);
|
|
350
348
|
}
|
|
349
|
+
if (!multiple) setOpen(false);
|
|
351
350
|
setInternalFilter("");
|
|
352
|
-
}, [onCreate, filter, multiple, value, onValueChange]);
|
|
351
|
+
}, [onCreate, filter, multiple, value, onValueChange, setOpen]);
|
|
353
352
|
const initialOrderRef = (0, import_react.useRef)(null);
|
|
354
353
|
const hasSearchedRef = (0, import_react.useRef)(false);
|
|
355
354
|
const sortedFiltered = (0, import_react.useMemo)(() => {
|
|
@@ -914,6 +913,7 @@ function FloatingComboboxCore({
|
|
|
914
913
|
lastKeyboardNavTimeRef.current = Date.now();
|
|
915
914
|
setActiveIndex(Math.max(0, totalNavigableItems - 1));
|
|
916
915
|
} else if (event.key === "Enter" || event.key === " ") {
|
|
916
|
+
if (event.key === " " && filter.trim()) return;
|
|
917
917
|
event.preventDefault();
|
|
918
918
|
if (activeIndex === createOptionIndex && showCreateOption) {
|
|
919
919
|
handleCreate();
|
|
@@ -929,7 +929,7 @@ function FloatingComboboxCore({
|
|
|
929
929
|
event.preventDefault();
|
|
930
930
|
setOpen(false);
|
|
931
931
|
}
|
|
932
|
-
}, [navigableOptions, activeIndex, handleSelect, handleCreate, totalNavigableItems, createOptionIndex, showCreateOption, multiple, setKeyboardNav]);
|
|
932
|
+
}, [navigableOptions, activeIndex, handleSelect, handleCreate, totalNavigableItems, createOptionIndex, showCreateOption, multiple, filter, setKeyboardNav]);
|
|
933
933
|
(0, import_react.useEffect)(() => {
|
|
934
934
|
if (activeIndex == null) return;
|
|
935
935
|
const scrollContainer = listScrollRef.current;
|
|
@@ -1406,19 +1406,18 @@ function NativeComboboxCore({
|
|
|
1406
1406
|
return !options.some(o => o.label.toLowerCase() === trimmed || o.value.toLowerCase() === trimmed);
|
|
1407
1407
|
}, [creatable, filter, options]);
|
|
1408
1408
|
const handleCreate = (0, import_react.useCallback)(() => {
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
setOpen(false);
|
|
1418
|
-
}
|
|
1409
|
+
const typed = filter.trim();
|
|
1410
|
+
if (!onCreate || !typed) return;
|
|
1411
|
+
const newOption = onCreate(typed);
|
|
1412
|
+
if (newOption && multiple) {
|
|
1413
|
+
const current = Array.isArray(value) ? value : value ? [value] : [];
|
|
1414
|
+
if (!current.includes(newOption.value)) onValueChange?.([...current, newOption.value]);
|
|
1415
|
+
} else if (newOption) {
|
|
1416
|
+
onValueChange?.(newOption.value);
|
|
1419
1417
|
}
|
|
1418
|
+
if (!multiple) setOpen(false);
|
|
1420
1419
|
setInternalFilter("");
|
|
1421
|
-
}, [onCreate, filter, multiple, value, onValueChange]);
|
|
1420
|
+
}, [onCreate, filter, multiple, value, onValueChange, setOpen]);
|
|
1422
1421
|
const hasScrollableContent = Boolean(onSearch) || filtered.length > 6;
|
|
1423
1422
|
const sheetTransition = knobProps.transition ?? "medium";
|
|
1424
1423
|
const sortedFiltered = (0, import_react.useMemo)(() => {
|
|
@@ -1986,6 +1985,18 @@ function Combobox({
|
|
|
1986
1985
|
const resolvedValidators = (0, import_utils.useResolvedValidators)(required, validators, label, name);
|
|
1987
1986
|
const [uncontrolledValue, setUncontrolledValue] = (0, import_react.useState)(defaultValue);
|
|
1988
1987
|
const isControlled = valueProp !== void 0;
|
|
1988
|
+
const [createdOptions, setCreatedOptions] = (0, import_react.useState)([]);
|
|
1989
|
+
const knownOptions = (0, import_react.useMemo)(() => {
|
|
1990
|
+
const unlisted = createdOptions.filter(c => !options.some(o => o.value === c.value));
|
|
1991
|
+
return unlisted.length ? [...options, ...unlisted] : options;
|
|
1992
|
+
}, [options, createdOptions]);
|
|
1993
|
+
const handleCreateOption = (0, import_react.useMemo)(() => onCreate && (typed => {
|
|
1994
|
+
const created = onCreate(typed);
|
|
1995
|
+
if (created) {
|
|
1996
|
+
setCreatedOptions(prev => prev.some(o => o.value === created.value) ? prev : [...prev, created]);
|
|
1997
|
+
}
|
|
1998
|
+
return created;
|
|
1999
|
+
}), [onCreate]);
|
|
1989
2000
|
const viewportGtSm = (0, import_FloatingPanel.useViewportGtSm)();
|
|
1990
2001
|
const effectiveGtSm = typeof window !== "undefined" ? viewportGtSm : false;
|
|
1991
2002
|
const shouldUseSheet = !import_tamagui.isWeb || !effectiveGtSm;
|
|
@@ -2006,7 +2017,7 @@ function Combobox({
|
|
|
2006
2017
|
}
|
|
2007
2018
|
const renderReadOnly = selectValue => {
|
|
2008
2019
|
if (multiple && Array.isArray(selectValue)) {
|
|
2009
|
-
const labels = selectValue.map(v =>
|
|
2020
|
+
const labels = selectValue.map(v => knownOptions.find(o => o.value === v)?.label ?? v).join(", ");
|
|
2010
2021
|
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Text, {
|
|
2011
2022
|
fontSize: knobProps.sizeToken,
|
|
2012
2023
|
color: textColor,
|
|
@@ -2018,7 +2029,7 @@ function Combobox({
|
|
|
2018
2029
|
});
|
|
2019
2030
|
}
|
|
2020
2031
|
const sv = typeof selectValue === "string" ? selectValue : void 0;
|
|
2021
|
-
const selected =
|
|
2032
|
+
const selected = knownOptions.find(option => option.value === sv);
|
|
2022
2033
|
const displayText = selected?.label ?? (sv ? valueLabel ?? sv : "-");
|
|
2023
2034
|
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Text, {
|
|
2024
2035
|
fontSize: knobProps.sizeToken,
|
|
@@ -2034,7 +2045,7 @@ function Combobox({
|
|
|
2034
2045
|
if (readOnly) return renderReadOnly(selectValue);
|
|
2035
2046
|
const ComboboxCore = shouldUseSheet ? NativeComboboxCore : FloatingComboboxCore;
|
|
2036
2047
|
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ComboboxCore, {
|
|
2037
|
-
options,
|
|
2048
|
+
options: onSearch ? options : knownOptions,
|
|
2038
2049
|
value: selectValue,
|
|
2039
2050
|
onValueChange: value => {
|
|
2040
2051
|
if (disabled) return;
|
|
@@ -2049,7 +2060,7 @@ function Combobox({
|
|
|
2049
2060
|
onSearch,
|
|
2050
2061
|
loading,
|
|
2051
2062
|
searchError,
|
|
2052
|
-
valueLabel,
|
|
2063
|
+
valueLabel: valueLabel ?? createdOptions.find(o => o.value === selectValue)?.label,
|
|
2053
2064
|
clearable,
|
|
2054
2065
|
onLoadMore,
|
|
2055
2066
|
hasMore,
|
|
@@ -2066,7 +2077,7 @@ function Combobox({
|
|
|
2066
2077
|
selectedOrder,
|
|
2067
2078
|
dismissible,
|
|
2068
2079
|
creatable,
|
|
2069
|
-
onCreate,
|
|
2080
|
+
onCreate: handleCreateOption,
|
|
2070
2081
|
createLabel,
|
|
2071
2082
|
hideSearch,
|
|
2072
2083
|
searchValue,
|
|
@@ -473,19 +473,18 @@ function FloatingComboboxCore(param) {
|
|
|
473
473
|
});
|
|
474
474
|
}, [creatable, filter, options]);
|
|
475
475
|
var handleCreate = (0, import_react.useCallback)(function () {
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
setOpen(false);
|
|
485
|
-
}
|
|
476
|
+
var typed = filter.trim();
|
|
477
|
+
if (!onCreate || !typed) return;
|
|
478
|
+
var newOption = onCreate(typed);
|
|
479
|
+
if (newOption && multiple) {
|
|
480
|
+
var current = Array.isArray(value) ? value : value ? [value] : [];
|
|
481
|
+
if (!current.includes(newOption.value)) onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange([...current, newOption.value]);
|
|
482
|
+
} else if (newOption) {
|
|
483
|
+
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(newOption.value);
|
|
486
484
|
}
|
|
485
|
+
if (!multiple) setOpen(false);
|
|
487
486
|
setInternalFilter("");
|
|
488
|
-
}, [onCreate, filter, multiple, value, onValueChange]);
|
|
487
|
+
}, [onCreate, filter, multiple, value, onValueChange, setOpen]);
|
|
489
488
|
var initialOrderRef = (0, import_react.useRef)(null);
|
|
490
489
|
var hasSearchedRef = (0, import_react.useRef)(false);
|
|
491
490
|
var sortedFiltered = (0, import_react.useMemo)(function () {
|
|
@@ -1096,6 +1095,7 @@ function FloatingComboboxCore(param) {
|
|
|
1096
1095
|
lastKeyboardNavTimeRef.current = Date.now();
|
|
1097
1096
|
setActiveIndex(Math.max(0, totalNavigableItems - 1));
|
|
1098
1097
|
} else if (event.key === "Enter" || event.key === " ") {
|
|
1098
|
+
if (event.key === " " && filter.trim()) return;
|
|
1099
1099
|
event.preventDefault();
|
|
1100
1100
|
if (activeIndex === createOptionIndex && showCreateOption) {
|
|
1101
1101
|
handleCreate();
|
|
@@ -1111,7 +1111,7 @@ function FloatingComboboxCore(param) {
|
|
|
1111
1111
|
event.preventDefault();
|
|
1112
1112
|
setOpen(false);
|
|
1113
1113
|
}
|
|
1114
|
-
}, [navigableOptions, activeIndex, handleSelect, handleCreate, totalNavigableItems, createOptionIndex, showCreateOption, multiple, setKeyboardNav]);
|
|
1114
|
+
}, [navigableOptions, activeIndex, handleSelect, handleCreate, totalNavigableItems, createOptionIndex, showCreateOption, multiple, filter, setKeyboardNav]);
|
|
1115
1115
|
(0, import_react.useEffect)(function () {
|
|
1116
1116
|
if (activeIndex == null) return;
|
|
1117
1117
|
var scrollContainer = listScrollRef.current;
|
|
@@ -1664,19 +1664,18 @@ function NativeComboboxCore(param) {
|
|
|
1664
1664
|
});
|
|
1665
1665
|
}, [creatable, filter, options]);
|
|
1666
1666
|
var handleCreate = (0, import_react.useCallback)(function () {
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
setOpen(false);
|
|
1676
|
-
}
|
|
1667
|
+
var typed = filter.trim();
|
|
1668
|
+
if (!onCreate || !typed) return;
|
|
1669
|
+
var newOption = onCreate(typed);
|
|
1670
|
+
if (newOption && multiple) {
|
|
1671
|
+
var current = Array.isArray(value) ? value : value ? [value] : [];
|
|
1672
|
+
if (!current.includes(newOption.value)) onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange([...current, newOption.value]);
|
|
1673
|
+
} else if (newOption) {
|
|
1674
|
+
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(newOption.value);
|
|
1677
1675
|
}
|
|
1676
|
+
if (!multiple) setOpen(false);
|
|
1678
1677
|
setInternalFilter("");
|
|
1679
|
-
}, [onCreate, filter, multiple, value, onValueChange]);
|
|
1678
|
+
}, [onCreate, filter, multiple, value, onValueChange, setOpen]);
|
|
1680
1679
|
var hasScrollableContent = Boolean(onSearch) || filtered.length > 6;
|
|
1681
1680
|
var sheetTransition = (_knobProps_transition = knobProps.transition) !== null && _knobProps_transition !== void 0 ? _knobProps_transition : "medium";
|
|
1682
1681
|
var sortedFiltered = (0, import_react.useMemo)(function () {
|
|
@@ -2281,6 +2280,28 @@ function Combobox(param) {
|
|
|
2281
2280
|
var resolvedValidators = (0, import_utils.useResolvedValidators)(required, validators, label, name);
|
|
2282
2281
|
var [uncontrolledValue, setUncontrolledValue] = (0, import_react.useState)(defaultValue);
|
|
2283
2282
|
var isControlled = valueProp !== void 0;
|
|
2283
|
+
var [createdOptions, setCreatedOptions] = (0, import_react.useState)([]);
|
|
2284
|
+
var knownOptions = (0, import_react.useMemo)(function () {
|
|
2285
|
+
var unlisted = createdOptions.filter(function (c) {
|
|
2286
|
+
return !options.some(function (o) {
|
|
2287
|
+
return o.value === c.value;
|
|
2288
|
+
});
|
|
2289
|
+
});
|
|
2290
|
+
return unlisted.length ? [...options, ...unlisted] : options;
|
|
2291
|
+
}, [options, createdOptions]);
|
|
2292
|
+
var handleCreateOption = (0, import_react.useMemo)(function () {
|
|
2293
|
+
return onCreate && function (typed) {
|
|
2294
|
+
var created = onCreate(typed);
|
|
2295
|
+
if (created) {
|
|
2296
|
+
setCreatedOptions(function (prev) {
|
|
2297
|
+
return prev.some(function (o) {
|
|
2298
|
+
return o.value === created.value;
|
|
2299
|
+
}) ? prev : [...prev, created];
|
|
2300
|
+
});
|
|
2301
|
+
}
|
|
2302
|
+
return created;
|
|
2303
|
+
};
|
|
2304
|
+
}, [onCreate]);
|
|
2284
2305
|
var viewportGtSm = (0, import_FloatingPanel.useViewportGtSm)();
|
|
2285
2306
|
var effectiveGtSm = typeof window !== "undefined" ? viewportGtSm : false;
|
|
2286
2307
|
var shouldUseSheet = !import_tamagui.isWeb || !effectiveGtSm;
|
|
@@ -2304,10 +2325,10 @@ function Combobox(param) {
|
|
|
2304
2325
|
if (multiple && Array.isArray(selectValue)) {
|
|
2305
2326
|
var labels = selectValue.map(function (v) {
|
|
2306
2327
|
var _ref2;
|
|
2307
|
-
var
|
|
2308
|
-
return (_ref2 = (
|
|
2328
|
+
var _knownOptions_find;
|
|
2329
|
+
return (_ref2 = (_knownOptions_find = knownOptions.find(function (o) {
|
|
2309
2330
|
return o.value === v;
|
|
2310
|
-
})) === null ||
|
|
2331
|
+
})) === null || _knownOptions_find === void 0 ? void 0 : _knownOptions_find.label) !== null && _ref2 !== void 0 ? _ref2 : v;
|
|
2311
2332
|
}).join(", ");
|
|
2312
2333
|
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Text, {
|
|
2313
2334
|
fontSize: knobProps.sizeToken,
|
|
@@ -2320,7 +2341,7 @@ function Combobox(param) {
|
|
|
2320
2341
|
});
|
|
2321
2342
|
}
|
|
2322
2343
|
var sv = typeof selectValue === "string" ? selectValue : void 0;
|
|
2323
|
-
var selected =
|
|
2344
|
+
var selected = knownOptions.find(function (option) {
|
|
2324
2345
|
return option.value === sv;
|
|
2325
2346
|
});
|
|
2326
2347
|
var displayText = (_ref = selected === null || selected === void 0 ? void 0 : selected.label) !== null && _ref !== void 0 ? _ref : sv ? valueLabel !== null && valueLabel !== void 0 ? valueLabel : sv : "-";
|
|
@@ -2335,10 +2356,11 @@ function Combobox(param) {
|
|
|
2335
2356
|
});
|
|
2336
2357
|
};
|
|
2337
2358
|
var renderComboboxContent = function renderComboboxContent2(selectValue, handleValueChange, handleBlur) {
|
|
2359
|
+
var _createdOptions_find;
|
|
2338
2360
|
if (readOnly) return renderReadOnly(selectValue);
|
|
2339
2361
|
var ComboboxCore = shouldUseSheet ? NativeComboboxCore : FloatingComboboxCore;
|
|
2340
2362
|
return /* @__PURE__ */(0, import_jsx_runtime.jsx)(ComboboxCore, {
|
|
2341
|
-
options,
|
|
2363
|
+
options: onSearch ? options : knownOptions,
|
|
2342
2364
|
value: selectValue,
|
|
2343
2365
|
onValueChange: function onValueChange1(value) {
|
|
2344
2366
|
if (disabled) return;
|
|
@@ -2353,7 +2375,9 @@ function Combobox(param) {
|
|
|
2353
2375
|
onSearch,
|
|
2354
2376
|
loading,
|
|
2355
2377
|
searchError,
|
|
2356
|
-
valueLabel
|
|
2378
|
+
valueLabel: valueLabel !== null && valueLabel !== void 0 ? valueLabel : (_createdOptions_find = createdOptions.find(function (o) {
|
|
2379
|
+
return o.value === selectValue;
|
|
2380
|
+
})) === null || _createdOptions_find === void 0 ? void 0 : _createdOptions_find.label,
|
|
2357
2381
|
clearable,
|
|
2358
2382
|
onLoadMore,
|
|
2359
2383
|
hasMore,
|
|
@@ -2370,7 +2394,7 @@ function Combobox(param) {
|
|
|
2370
2394
|
selectedOrder,
|
|
2371
2395
|
dismissible,
|
|
2372
2396
|
creatable,
|
|
2373
|
-
onCreate,
|
|
2397
|
+
onCreate: handleCreateOption,
|
|
2374
2398
|
createLabel,
|
|
2375
2399
|
hideSearch,
|
|
2376
2400
|
searchValue,
|