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:
parent
7d8623de89
commit
922676a7cc
2 changed files with 32 additions and 0 deletions
|
@ -99,6 +99,8 @@ export const AutocompleteInput: React.FC<AutocompleteInputProps> = ({
|
||||||
|
|
||||||
onSelectionChange(newSelection);
|
onSelectionChange(newSelection);
|
||||||
focusEditor();
|
focusEditor();
|
||||||
|
setQuery("");
|
||||||
|
setSuggestions([]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeSelection = (completion: ICompletion): void => {
|
const removeSelection = (completion: ICompletion): void => {
|
||||||
|
|
|
@ -246,6 +246,36 @@ describe("AutocompleteInput", () => {
|
||||||
expect(onSelectionChangeMock).toHaveBeenCalledWith([mockCompletion[0]]);
|
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(() => {
|
afterAll(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
jest.resetModules();
|
jest.resetModules();
|
||||||
|
|
Loading…
Reference in a new issue