@economic/taco 3.0.0-test-breaking-change.0 → 3.0.0-value-renderer.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/taco.cjs +41 -7
- package/dist/taco.cjs.map +1 -1
- package/dist/taco.d.ts +2 -0
- package/dist/taco.js +41 -7
- package/dist/taco.js.map +1 -1
- package/package.json +2 -2
package/dist/taco.cjs
CHANGED
|
@@ -25275,7 +25275,7 @@ const filterData = (data, value = "") => {
|
|
|
25275
25275
|
return data.filter(({ value: value2 }) => filteredOptionValues.has(value2));
|
|
25276
25276
|
};
|
|
25277
25277
|
const debouncer = debounce$2((f2) => f2(), 200);
|
|
25278
|
-
const
|
|
25278
|
+
const defaultConvertToInputValue = (value) => String(value ?? "");
|
|
25279
25279
|
const useCombobox = (props, ref) => {
|
|
25280
25280
|
const {
|
|
25281
25281
|
"aria-label": ariaLabel,
|
|
@@ -25292,6 +25292,7 @@ const useCombobox = (props, ref) => {
|
|
|
25292
25292
|
onSearch,
|
|
25293
25293
|
readOnly,
|
|
25294
25294
|
value,
|
|
25295
|
+
valueRenderer,
|
|
25295
25296
|
...otherProps
|
|
25296
25297
|
} = props;
|
|
25297
25298
|
const inputRef = useMergedRef(ref);
|
|
@@ -25299,9 +25300,19 @@ const useCombobox = (props, ref) => {
|
|
|
25299
25300
|
const listRef = React__namespace.useRef(null);
|
|
25300
25301
|
const [open, setOpen] = React__namespace.useState(false);
|
|
25301
25302
|
const listId = React__namespace.useMemo(() => nanoid(), []);
|
|
25303
|
+
const flattenedData = useFlattenedData(unfilteredData);
|
|
25304
|
+
const convertToInputValue = React__namespace.useCallback(
|
|
25305
|
+
(val) => {
|
|
25306
|
+
if (valueRenderer) {
|
|
25307
|
+
const option = findByValue(flattenedData, val);
|
|
25308
|
+
return valueRenderer(option);
|
|
25309
|
+
}
|
|
25310
|
+
return defaultConvertToInputValue(val);
|
|
25311
|
+
},
|
|
25312
|
+
[valueRenderer, flattenedData]
|
|
25313
|
+
);
|
|
25302
25314
|
const [inputValue, setInputValue] = React__namespace.useState(convertToInputValue(value));
|
|
25303
25315
|
const shouldFilterData = !onSearch && (!inline || inline && inputValue !== convertToInputValue(value));
|
|
25304
|
-
const flattenedData = useFlattenedData(unfilteredData);
|
|
25305
25316
|
const data = React__namespace.useMemo(
|
|
25306
25317
|
() => shouldFilterData ? filterData(flattenedData, inputValue) : flattenedData,
|
|
25307
25318
|
[shouldFilterData, inputValue, flattenedData]
|
|
@@ -25335,8 +25346,11 @@ const useCombobox = (props, ref) => {
|
|
|
25335
25346
|
}
|
|
25336
25347
|
}, [data]);
|
|
25337
25348
|
React__namespace.useEffect(() => {
|
|
25338
|
-
if (value !== void 0
|
|
25339
|
-
|
|
25349
|
+
if (value !== void 0) {
|
|
25350
|
+
const renderedValue = convertToInputValue(value);
|
|
25351
|
+
if (renderedValue !== inputValue) {
|
|
25352
|
+
setInputValue(renderedValue);
|
|
25353
|
+
}
|
|
25340
25354
|
}
|
|
25341
25355
|
}, [value]);
|
|
25342
25356
|
React__namespace.useEffect(() => {
|
|
@@ -25347,7 +25361,7 @@ const useCombobox = (props, ref) => {
|
|
|
25347
25361
|
}
|
|
25348
25362
|
}, [inputValue]);
|
|
25349
25363
|
React__namespace.useEffect(() => {
|
|
25350
|
-
const isCurrentValue = value !== void 0 && value !== null && inputValue ===
|
|
25364
|
+
const isCurrentValue = value !== void 0 && value !== null && inputValue === convertToInputValue(value);
|
|
25351
25365
|
if (inputValue && data.length && !isCurrentValue) {
|
|
25352
25366
|
setCurrentIndex(getIndexFromValue(data, inputValue) || 0);
|
|
25353
25367
|
if (!open) {
|
|
@@ -25364,14 +25378,34 @@ const useCombobox = (props, ref) => {
|
|
|
25364
25378
|
setCurrentIndex(void 0);
|
|
25365
25379
|
}
|
|
25366
25380
|
}, [open]);
|
|
25381
|
+
const findOption = React__namespace.useCallback(
|
|
25382
|
+
(inputVal) => {
|
|
25383
|
+
const itemByValue = findByValue(flattenedData, inputVal);
|
|
25384
|
+
if (itemByValue) {
|
|
25385
|
+
return itemByValue;
|
|
25386
|
+
}
|
|
25387
|
+
if (valueRenderer) {
|
|
25388
|
+
return flattenedData.find((option) => valueRenderer(option) === inputVal);
|
|
25389
|
+
}
|
|
25390
|
+
return void 0;
|
|
25391
|
+
},
|
|
25392
|
+
[flattenedData, valueRenderer]
|
|
25393
|
+
);
|
|
25367
25394
|
const handleInputBlur = (event) => {
|
|
25368
25395
|
event.persist();
|
|
25369
25396
|
if (listRef.current && event.relatedTarget === listRef.current) {
|
|
25370
25397
|
event.preventDefault();
|
|
25371
25398
|
return;
|
|
25372
25399
|
}
|
|
25373
|
-
|
|
25374
|
-
|
|
25400
|
+
const item = findOption(event.target.value);
|
|
25401
|
+
if (item && item.value === value) {
|
|
25402
|
+
setInputValue(convertToInputValue(value));
|
|
25403
|
+
if (props.onBlur) {
|
|
25404
|
+
props.onBlur(event);
|
|
25405
|
+
}
|
|
25406
|
+
return;
|
|
25407
|
+
}
|
|
25408
|
+
if (onChange && event.target.value !== convertToInputValue(value)) {
|
|
25375
25409
|
event.detail = sanitizeItem(item);
|
|
25376
25410
|
const parents = getOptionParents(flattenedData, item == null ? void 0 : item.path);
|
|
25377
25411
|
if (parents !== null && parents.length > 0) {
|