mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
parent
95c06a83b3
commit
632320ae3b
2 changed files with 27 additions and 1 deletions
|
@ -339,7 +339,7 @@
|
||||||
} else if (key === "ArrowUp") {
|
} else if (key === "ArrowUp") {
|
||||||
change(-1);
|
change(-1);
|
||||||
} else if (key === "Escape") {
|
} else if (key === "Escape") {
|
||||||
open = false;
|
clear();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
on:keyup
|
on:keyup
|
||||||
|
|
|
@ -305,6 +305,8 @@ describe("ComboBox", () => {
|
||||||
it("should close menu on Escape key", async () => {
|
it("should close menu on Escape key", async () => {
|
||||||
render(ComboBox);
|
render(ComboBox);
|
||||||
|
|
||||||
|
expect(screen.getByRole("textbox")).toHaveValue("");
|
||||||
|
|
||||||
const input = screen.getByRole("textbox");
|
const input = screen.getByRole("textbox");
|
||||||
await user.click(input);
|
await user.click(input);
|
||||||
|
|
||||||
|
@ -313,6 +315,30 @@ describe("ComboBox", () => {
|
||||||
|
|
||||||
await user.keyboard("{Escape}");
|
await user.keyboard("{Escape}");
|
||||||
expect(dropdown).not.toBeVisible();
|
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 () => {
|
it("should use custom shouldFilterItem function", async () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue