@economic/taco 3.0.0-test-breaking-change.0 → 3.0.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.d.ts CHANGED
@@ -655,6 +655,8 @@ declare type ComboboxBaseProps = Omit<InputProps, 'defaultValue' | 'button' | 'o
655
655
  onSearch?: (query: string) => void | Promise<void>;
656
656
  /** Value of the input in combobox */
657
657
  value?: ComboboxValue;
658
+ /** Custom renderer for displaying the selected value in the input field. If not provided, defaults to displaying the option's value. */
659
+ valueRenderer?: (option: ComboboxItem | undefined) => string;
658
660
  };
659
661
 
660
662
  export declare type ComboboxItem = ScrollableListItem;
package/dist/taco.js CHANGED
@@ -25257,7 +25257,7 @@ const filterData = (data, value = "") => {
25257
25257
  return data.filter(({ value: value2 }) => filteredOptionValues.has(value2));
25258
25258
  };
25259
25259
  const debouncer = debounce$2((f2) => f2(), 200);
25260
- const convertToInputValue = (value) => String(value ?? "");
25260
+ const defaultConvertToInputValue = (value) => String(value ?? "");
25261
25261
  const useCombobox = (props, ref) => {
25262
25262
  const {
25263
25263
  "aria-label": ariaLabel,
@@ -25274,6 +25274,7 @@ const useCombobox = (props, ref) => {
25274
25274
  onSearch,
25275
25275
  readOnly,
25276
25276
  value,
25277
+ valueRenderer,
25277
25278
  ...otherProps
25278
25279
  } = props;
25279
25280
  const inputRef = useMergedRef(ref);
@@ -25281,9 +25282,19 @@ const useCombobox = (props, ref) => {
25281
25282
  const listRef = React.useRef(null);
25282
25283
  const [open, setOpen] = React.useState(false);
25283
25284
  const listId = React.useMemo(() => nanoid(), []);
25285
+ const flattenedData = useFlattenedData(unfilteredData);
25286
+ const convertToInputValue = React.useCallback(
25287
+ (val) => {
25288
+ const option = findByValue(flattenedData, val);
25289
+ if (typeof valueRenderer === "function" && option) {
25290
+ return valueRenderer(option);
25291
+ }
25292
+ return defaultConvertToInputValue(val);
25293
+ },
25294
+ [valueRenderer, flattenedData]
25295
+ );
25284
25296
  const [inputValue, setInputValue] = React.useState(convertToInputValue(value));
25285
25297
  const shouldFilterData = !onSearch && (!inline || inline && inputValue !== convertToInputValue(value));
25286
- const flattenedData = useFlattenedData(unfilteredData);
25287
25298
  const data = React.useMemo(
25288
25299
  () => shouldFilterData ? filterData(flattenedData, inputValue) : flattenedData,
25289
25300
  [shouldFilterData, inputValue, flattenedData]
@@ -25317,8 +25328,11 @@ const useCombobox = (props, ref) => {
25317
25328
  }
25318
25329
  }, [data]);
25319
25330
  React.useEffect(() => {
25320
- if (value !== void 0 && value !== inputValue) {
25321
- setInputValue(convertToInputValue(value));
25331
+ if (value !== void 0) {
25332
+ const renderedValue = convertToInputValue(value);
25333
+ if (renderedValue !== inputValue) {
25334
+ setInputValue(renderedValue);
25335
+ }
25322
25336
  }
25323
25337
  }, [value]);
25324
25338
  React.useEffect(() => {
@@ -25329,7 +25343,7 @@ const useCombobox = (props, ref) => {
25329
25343
  }
25330
25344
  }, [inputValue]);
25331
25345
  React.useEffect(() => {
25332
- const isCurrentValue = value !== void 0 && value !== null && inputValue === String(value);
25346
+ const isCurrentValue = value !== void 0 && value !== null && inputValue === convertToInputValue(value);
25333
25347
  if (inputValue && data.length && !isCurrentValue) {
25334
25348
  setCurrentIndex(getIndexFromValue(data, inputValue) || 0);
25335
25349
  if (!open) {
@@ -25346,14 +25360,34 @@ const useCombobox = (props, ref) => {
25346
25360
  setCurrentIndex(void 0);
25347
25361
  }
25348
25362
  }, [open]);
25363
+ const findOption = React.useCallback(
25364
+ (inputVal) => {
25365
+ const itemByValue = findByValue(flattenedData, inputVal);
25366
+ if (itemByValue) {
25367
+ return itemByValue;
25368
+ }
25369
+ if (valueRenderer) {
25370
+ return flattenedData.find((option) => valueRenderer(option) === inputVal);
25371
+ }
25372
+ return void 0;
25373
+ },
25374
+ [flattenedData, valueRenderer]
25375
+ );
25349
25376
  const handleInputBlur = (event) => {
25350
25377
  event.persist();
25351
25378
  if (listRef.current && event.relatedTarget === listRef.current) {
25352
25379
  event.preventDefault();
25353
25380
  return;
25354
25381
  }
25355
- if (onChange && event.target.value !== String(value)) {
25356
- const item = findByValue(flattenedData, event.target.value);
25382
+ const item = findOption(event.target.value);
25383
+ if (item && item.value === value) {
25384
+ setInputValue(convertToInputValue(value));
25385
+ if (props.onBlur) {
25386
+ props.onBlur(event);
25387
+ }
25388
+ return;
25389
+ }
25390
+ if (onChange && event.target.value !== convertToInputValue(value)) {
25357
25391
  event.detail = sanitizeItem(item);
25358
25392
  const parents = getOptionParents(flattenedData, item == null ? void 0 : item.path);
25359
25393
  if (parents !== null && parents.length > 0) {