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

fix(combobox): prevent spacebar from opening the menu while focusing on chip's close button #8909

Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions packages/calcite-components/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ export namespace Components {
*/
"disabled": boolean;
/**
* Specifies the optional new name of the file after it is downloaded.
* Prompts the user to save the linked URL instead of navigating to it. Can be used with or without a value: Without a value, the browser will suggest a filename/extension See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download.
*/
"download": string | boolean;
/**
Expand Down Expand Up @@ -8059,7 +8059,7 @@ declare namespace LocalJSX {
*/
"disabled"?: boolean;
/**
* Specifies the optional new name of the file after it is downloaded.
* Prompts the user to save the linked URL instead of navigating to it. Can be used with or without a value: Without a value, the browser will suggest a filename/extension See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download.
*/
"download"?: string | boolean;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1918,4 +1918,58 @@ describe("calcite-combobox", () => {
});
});
});

it("should not open combobox menu with spacebar while focusing on chip's close button", async () => {
const page = await newE2EPage();
await page.setContent(html`
<calcite-combobox label="test" placeholder="placeholder" max-items="10" scale="m">
<calcite-combobox-item-group label="Pokemon">
<calcite-combobox-item value="Pikachu" text-label="Pikachu"></calcite-combobox-item>
<calcite-combobox-item value="Venusaur" text-label="Venusaur"></calcite-combobox-item>
<calcite-combobox-item value="Charizard" text-label="Charizard"></calcite-combobox-item>
<calcite-combobox-item-group label="Cutest Pokemon">
<calcite-combobox-item value="Bulbasaur" text-label="Bulbasaur"></calcite-combobox-item>
<calcite-combobox-item value="Squirtle1" text-label="Squirtle1">
<calcite-combobox-item value="Squirtle2" text-label="Squirtle2">
<calcite-combobox-item value="Squirtle3" text-label="Squirtle3">
<calcite-combobox-item value="Squirtle4" text-label="Squirtle4"></calcite-combobox-item>
</calcite-combobox-item>
</calcite-combobox-item>
</calcite-combobox-item>
</calcite-combobox-item-group>
</calcite-combobox-item-group>
</calcite-combobox>
`);

const combobox = await page.find("calcite-combobox");
const openEvent = page.waitForEvent("calciteComboboxOpen");
await combobox.click();
await openEvent;

const item1 = await combobox.find("calcite-combobox-item[value=Pikachu]");
await item1.click();
const item2 = await combobox.find("calcite-combobox-item[value=Charizard]");
await item2.click();
const item3 = await combobox.find("calcite-combobox-item[value=Squirtle3]");
await item3.click();

const chips = await page.findAll("calcite-combobox >>> calcite-chip");
expect(chips.length).toBe(3);

const closeEvent = page.waitForEvent("calciteComboboxClose");
await combobox.press("Tab");
await closeEvent;

await page.evaluate(() => {
const combobox = document.querySelector("calcite-combobox");
const chip = combobox.shadowRoot.querySelector("calcite-chip");
const closeButton = chip.shadowRoot.querySelector(".close");
(closeButton as HTMLElement).click();
});
await page.waitForChanges();

const remainingChips = await page.findAll("calcite-combobox >>> calcite-chip");
expect(remainingChips.length).toBe(2);
expect(await page.find("calcite-combobox")).not.toHaveAttribute("open");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,10 @@ export class Combobox
}
event.preventDefault();
}

if ((event.target as HTMLElement).closest("calcite-chip")) {
event.stopPropagation();
}
break;
case "Home":
if (!this.open) {
Expand Down
Loading