Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty suggestions list after selecting #40

Merged
merged 1 commit into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/three-clouds-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-loqate": patch
---

fix: empty the suggestions list when a selection is made
13 changes: 9 additions & 4 deletions src/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ it('renders default', async () => {
expect(baseElement).toMatchSnapshot();
});

it('calls the onSelect function', async () => {
it('calls the onSelect function and closes the suggestion list after selecting an item', async () => {
const onSelectFn = vi.fn();

render(
Expand All @@ -44,14 +44,19 @@ it('calls the onSelect function', async () => {
const input = screen.getByRole('textbox');
fireEvent.change(input, { target: { value: 'a' } });

const listItems = await screen.findAllByRole('listitem');
const firstListItem = listItems[0];
fireEvent.click(firstListItem);
const list = await screen.findByRole('list');
expect(list.childNodes).toHaveLength(10);
expect(list.hidden).toBe(false);

fireEvent.click(list.firstChild as Element);

await waitFor(() => {
expect(onSelectFn.mock.calls.length).toBe(1);
expect(onSelectFn).toHaveBeenCalledWith(selection.Items[0]);
});

expect(list.childNodes).toHaveLength(0);
expect(list.hidden).toBe(true);
});

it('allows for alternative url', async () => {
Expand Down
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ function AddressSearch(props: Props): JSX.Element {
}

onSelect(Items[0] as unknown as Address);
setSuggestions([]);
return;
}

Expand Down
Loading