Skip to content

Commit

Permalink
fix(combobox): convert textValue with optionTextValue (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich authored Jun 29, 2024
1 parent 5ef35cf commit 35f3988
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/core/src/combobox/combobox-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,22 @@ export function ComboboxBase<
);
};

const getOptionTextValue = (option: Option) => {
const optionTextValue = local.optionTextValue;

if (optionTextValue == null) {
// If no `optionTextValue`, the option itself is the label (ex: string[] of options).
return String(option);
}

// Get the label from the option object as a string.
return String(
isFunction(optionTextValue)
? optionTextValue(option as any)
: (option as any)[optionTextValue],
);
};

// All options flattened without option groups.
const allOptions = createMemo(() => {
const optionGroupChildren = local.optionGroupChildren;
Expand All @@ -454,7 +470,7 @@ export function ComboboxBase<
return local.defaultFilter?.(option as any, inputVal);
}

const textVal = getOptionLabel(option);
const textVal = getOptionTextValue(option);

switch (local.defaultFilter) {
case "startsWith":
Expand Down

0 comments on commit 35f3988

Please sign in to comment.