Skip to content

Commit

Permalink
Merge pull request #40 from labd/emptySuggestions
Browse files Browse the repository at this point in the history
fix: empty suggestions list after selecting
  • Loading branch information
BramKaashoek authored Jun 17, 2024
2 parents 99e8322 + 13efaee commit 959e52d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
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

0 comments on commit 959e52d

Please sign in to comment.