diff --git a/components/lib/autocomplete/AutoComplete.js b/components/lib/autocomplete/AutoComplete.js index a51b764225..63176353b1 100644 --- a/components/lib/autocomplete/AutoComplete.js +++ b/components/lib/autocomplete/AutoComplete.js @@ -152,13 +152,15 @@ export const AutoComplete = React.memo( selectedItem.current = ObjectUtils.isNotEmpty(value) ? value : null; }; - const formatValue = (value, useTemplate = false) => { + const formatValue = (value) => { if (ObjectUtils.isEmpty(value)) return ''; if (typeof value === 'string') return value; - if (useTemplate && props.selectedItemTemplate) { - return ObjectUtils.getJSXElement(props.selectedItemTemplate, value) || value; + const valueFromTemplate = ObjectUtils.getJSXElement(props.selectedItemTemplate, value); + + if (typeof valueFromTemplate === 'string') { + return valueFromTemplate; } if (props.field) { @@ -604,7 +606,7 @@ export const AutoComplete = React.memo( return (
  • - {formatValue(val, true)} + {formatValue(val)} {removeTokenIcon}
  • ); diff --git a/components/lib/autocomplete/autocomplete.d.ts b/components/lib/autocomplete/autocomplete.d.ts index 7cdbf29d39..c7981c5c59 100755 --- a/components/lib/autocomplete/autocomplete.d.ts +++ b/components/lib/autocomplete/autocomplete.d.ts @@ -406,7 +406,7 @@ export interface AutoCompleteProps extends Omit React.ReactNode); + selectedItemTemplate?: string | undefined | null | ((value: any) => string | undefined | null); /** * Whether to show the empty message or not. * @defaultValue false