Clear autocomplete input on selection accept (#12709)

* Clear autocomplete input on selection accept

Fixes https://github.com/element-hq/element-web/issues/27194

* Playwright: use rust crypto for the bot user (#12708)

... because legacy crypto is legacy

---------

Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
This commit is contained in:
David Baker 2024-07-02 10:38:20 +01:00 committed by GitHub
parent 7d8623de89
commit 922676a7cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View file

@ -99,6 +99,8 @@ export const AutocompleteInput: React.FC<AutocompleteInputProps> = ({
onSelectionChange(newSelection);
focusEditor();
setQuery("");
setSuggestions([]);
};
const removeSelection = (completion: ICompletion): void => {

View file

@ -246,6 +246,36 @@ describe("AutocompleteInput", () => {
expect(onSelectionChangeMock).toHaveBeenCalledWith([mockCompletion[0]]);
});
it("should clear text field and suggestions when a suggestion is accepted", async () => {
const mockProvider = constructMockProvider(mockCompletion);
const onSelectionChangeMock = jest.fn();
const { container } = render(
<AutocompleteInput
provider={mockProvider}
placeholder="Search ..."
selection={[]}
onSelectionChange={onSelectionChangeMock}
/>,
);
const input = getEditorInput();
act(() => {
fireEvent.focus(input);
fireEvent.change(input, { target: { value: "user" } });
});
const suggestions = await within(container).findAllByTestId("autocomplete-suggestion-item", { exact: false });
act(() => {
fireEvent.mouseDown(suggestions[0]);
});
expect(input).toHaveValue("");
expect(within(container).queryAllByTestId("autocomplete-suggestion-item", { exact: false })).toHaveLength(0);
});
afterAll(() => {
jest.clearAllMocks();
jest.resetModules();