Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function createAutocompleteIndexComponent({ createElement }: Renderer) {
);
return (
<li
key={item.objectID}
key={`${itemProps.id}:${item.objectID}`}
{...itemProps}
className={cx(
'ais-AutocompleteIndexItem',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ export function createAutocompletePanelComponent({ createElement }: Renderer) {
classNames.root,
props.className
)}
onMouseDown={(event: React.MouseEvent<HTMLDivElement>) => {
// Prevents the autocomplete panel from blurring the input when
// clicking inside the panel.
event.preventDefault();
}}
>
<div className={cx('ais-AutocompletePanelLayout', classNames.layout)}>
{children}
Expand Down
61 changes: 61 additions & 0 deletions tests/common/widgets/autocomplete/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -999,5 +999,66 @@ export function createOptionsTests(
expect(hiItem).not.toHaveClass('ais-ReverseHighlight-highlighted');
expect(hiItem).not.toHaveClass('ais-ReverseHighlight-nonHighlighted');
});

test('keeps input focused when clicking inside the panel', async () => {
const searchClient = createMockedSearchClient(
createMultiSearchResponse(
createSingleSearchResponse({
index: 'indexName',
hits: [{ objectID: '1', name: 'Item 1' }],
})
)
);

await setup({
instantSearchOptions: {
indexName: 'indexName',
searchClient,
},
widgetParams: {
javascript: {
indices: [
{
indexName: 'indexName',
templates: {
item: (props) => props.item.name,
},
},
],
},
react: {
indices: [
{
indexName: 'indexName',
itemComponent: (props) => props.item.name,
},
],
},
vue: {},
},
});

await act(async () => {
await wait(0);
});

const input = screen.getByRole('combobox', { name: /submit/i });

await act(async () => {
userEvent.click(input);
await wait(0);
});

expect(input).toHaveFocus();

const panel = document.querySelector('.ais-AutocompletePanel')!;

await act(async () => {
userEvent.click(panel);
await wait(0);
});

expect(input).toHaveFocus();
});
});
}