Skip to content

Commit

Permalink
fix: combobox primitive empty state when autocomplete is none (#1816)
Browse files Browse the repository at this point in the history
  • Loading branch information
HichamELBSI authored Nov 7, 2024
2 parents d7befb6 + f2ad83e commit 741c3f2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/blue-humans-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@strapi/ui-primitives': major
---

fixes the combobox primitive empty state when autocomplete is set to none
21 changes: 21 additions & 0 deletions packages/primitives/src/components/Combobox/Combobox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -965,5 +965,26 @@ describe('Combobox', () => {

expect(getByRole('option')).toBeInTheDocument();
});

it('should not render the "no result found." when the autocomplete is set to none and options are not empty', async () => {
const { getByRole, queryByText, user } = render({
autocomplete: 'none',
});

await user.click(getByRole('combobox'));

expect(queryByText('No value found')).not.toBeInTheDocument();
});

it('should render the "no result found." when the autocomplete is set to none and options are empty', async () => {
const { getByRole, getByText, user } = render({
options: [],
autocomplete: 'none',
});

await user.click(getByRole('combobox'));

expect(getByText('No value found')).toBeInTheDocument();
});
});
});
2 changes: 2 additions & 0 deletions packages/primitives/src/components/Combobox/Combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,8 @@ const ComboboxNoValueFound = React.forwardRef<HTMLDivElement, NoValueFoundProps>
};
}, [subscribe]);

if (autocomplete.type === 'none' && items.length > 0) return null;

if (
autocomplete.type === 'list' &&
autocomplete.filter === 'startsWith' &&
Expand Down

0 comments on commit 741c3f2

Please sign in to comment.