Skip to content

Commit

Permalink
fix(autocomplete-js): avoid warning when renderer is not specified at…
Browse files Browse the repository at this point in the history
… all (#947)
  • Loading branch information
sarahdayan authored Apr 12, 2022
1 parent 4c812c8 commit 5fbae0d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions packages/autocomplete-js/src/__tests__/renderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,41 @@ describe('renderer', () => {
);
});

test('does not warn at all when only passing a `render` option', () => {
const container = document.createElement('div');
const panelContainer = document.createElement('div');

document.body.appendChild(panelContainer);

expect(() => {
autocomplete<{ label: string }>({
container,
panelContainer,
initialState: {
isOpen: true,
},
getSources() {
return [
{
sourceId: 'testSource',
getItems() {
return [{ label: '1' }];
},
templates: {
item({ item }) {
return item.label;
},
},
},
];
},
render({ children, render }, root) {
render(children, root);
},
});
}).not.toWarnDev();
});

test('does not warn at all when not passing a custom renderer', () => {
const container = document.createElement('div');
const panelContainer = document.createElement('div');
Expand Down
2 changes: 1 addition & 1 deletion packages/autocomplete-js/src/getDefaultOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function getDefaultOptions<TItem extends BaseItem>(
);

warn(
Boolean(!render || renderer?.render),
!(render && renderer && !renderer?.render),
`You provided the \`render\` option but did not provide a \`renderer.render\`. Since v1.6.0, you can provide a \`render\` function directly in \`renderer\`.` +
`\nTo get rid of this warning, do any of the following depending on your use case.` +
"\n- If you are using the `render` option only to override Autocomplete's default `render` function, pass the `render` function into `renderer` and remove the `render` option." +
Expand Down

0 comments on commit 5fbae0d

Please sign in to comment.