Skip to content

Commit 3eb8ca8

Browse files
ernst-devNathanZlion
authored andcommitted
fix: Autosuggest custom rendering group and use-entered text not rendering correctly (#4489)
1 parent ed438bc commit 3eb8ca8

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

src/autosuggest/__tests__/render-option.test.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ describe('Autosuggest renderOption', () => {
231231
);
232232
});
233233

234-
test('does not render custom content for entered-text option', () => {
234+
test('renders custom content for entered-text option', () => {
235235
const renderOption = jest.fn(props => {
236236
if (props.item.type === 'entered-text') {
237237
return <div>Use custom: {props.item.option.value}</div>;
@@ -248,8 +248,7 @@ describe('Autosuggest renderOption', () => {
248248

249249
const enteredTextOption = wrapper.findEnteredTextOption();
250250
expect(enteredTextOption).not.toBe(null);
251-
// entered-text options always use option.label, ignoring renderOption
252-
expect(enteredTextOption!.getElement()).toHaveTextContent('Use value');
251+
expect(enteredTextOption!.getElement()).toHaveTextContent('Use custom: custom-value');
253252
});
254253

255254
test('maintains option index in item properties', () => {

src/autosuggest/autosuggest-option.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ const AutosuggestOption = (
150150

151151
let optionContent;
152152
if (useEntered) {
153-
optionContent = option.label;
153+
optionContent = renderResult ?? option.label;
154154
// we don't want fancy generated content for screenreader for the "Use..." option,
155155
// just the visible text is fine
156156
screenReaderContent = undefined;
157157
} else if (isParent) {
158-
optionContent = option.label;
158+
optionContent = renderResult ?? option.label;
159159
} else {
160160
const a11yProperties: AutosuggestOptionProps['nativeAttributes'] = {};
161161
if (nativeAttributes['aria-label']) {

0 commit comments

Comments
 (0)