fix(combo-box): "Escape" key clears input value (#2169)

Fixes #2167
This commit is contained in:
Eric Liu 2025-06-07 12:45:32 -07:00 committed by GitHub
commit 632320ae3b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View file

@ -305,6 +305,8 @@ describe("ComboBox", () => {
it("should close menu on Escape key", async () => {
render(ComboBox);
expect(screen.getByRole("textbox")).toHaveValue("");
const input = screen.getByRole("textbox");
await user.click(input);
@ -313,6 +315,30 @@ describe("ComboBox", () => {
await user.keyboard("{Escape}");
expect(dropdown).not.toBeVisible();
expect(screen.getByRole("textbox")).toHaveValue("");
expect(screen.getByRole("textbox")).toHaveFocus();
});
it("should close menu and clear selection on Escape key", async () => {
render(ComboBox, {
props: {
selectedId: "1",
value: "Email",
},
});
expect(screen.getByRole("textbox")).toHaveValue("Email");
const input = screen.getByRole("textbox");
await user.click(input);
const dropdown = screen.getAllByRole("listbox")[1];
expect(dropdown).toBeVisible();
await user.keyboard("{Escape}");
expect(dropdown).not.toBeVisible();
expect(screen.getByRole("textbox")).toHaveValue("");
expect(screen.getByRole("textbox")).toHaveFocus();
});
it("should use custom shouldFilterItem function", async () => {