Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using Tab to select the active option in the suggest box #3288

Merged
merged 1 commit into from
Jan 30, 2024
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 @@ -207,9 +207,9 @@ export const SuggestBox = <
"aria-autocomplete": "list",
"aria-label": ariaLabel,
onKeyDown: (event) => {
// When the user presses the enter key, select the active item
// When the user presses the enter or tab key, select the active item
if (
event.key === "Enter" &&
(event.key === "Enter" || event.key === "Tab") &&
activeIndex !== null &&
suggestionItems[activeIndex]
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,58 @@ describe("SuggestBox", () => {
expect(screen.getByRole("option")).toHaveTextContent("Parameter[1]");
});

it("closes the options when selecting an option", async () => {
it("selects an option using Enter", async () => {
render({
value: "Argument[block].1",
});

await userEvent.click(screen.getByRole("combobox"));
await userEvent.keyboard("{Enter}");

expect(onChange).toHaveBeenCalledWith("Argument[block].Parameter[1]");
});

it("selects an option using Tab", async () => {
render({
value: "Argument[block].1",
});

await userEvent.click(screen.getByRole("combobox"));
await userEvent.keyboard("{Enter}");

expect(onChange).toHaveBeenCalledWith("Argument[block].Parameter[1]");
});

it("does not select an option using Home", async () => {
render({
value: "Argument[block].1",
});

await userEvent.click(screen.getByRole("combobox"));
await userEvent.keyboard("{Home}");

expect(onChange).not.toHaveBeenCalled();
});

it("closes the options when selecting an option using Enter", async () => {
render({
value: "Argument[block].1",
});

await userEvent.click(screen.getByRole("combobox"));
await userEvent.keyboard("{Enter}");

expect(screen.queryByRole("option")).not.toBeInTheDocument();
});

it("closes the options when selecting an option using Tab", async () => {
render({
value: "Argument[block].1",
});

await userEvent.click(screen.getByRole("combobox"));
await userEvent.keyboard("{Tab}");

expect(screen.queryByRole("option")).not.toBeInTheDocument();
});

Expand Down
Loading