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): fix error that occurs when a click is emitted when the component is appended to the DOM #9380

Merged
merged 1 commit into from
May 21, 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 @@ -15,7 +15,7 @@ import {
import { html } from "../../../support/formatting";
import { CSS as ComboboxItemCSS } from "../combobox-item/resources";
import { CSS as XButtonCSS } from "../functional/XButton";
import { getElementXY, skipAnimations } from "../../tests/utils";
import { getElementXY, newProgrammaticE2EPage, skipAnimations } from "../../tests/utils";
import { CSS } from "./resources";

const selectionModes = ["single", "single-persist", "ancestors", "multiple"];
Expand Down Expand Up @@ -2020,4 +2020,14 @@ describe("calcite-combobox", () => {

expect(await combobox.getProperty("open")).toBe(false);
});

it("does not throw an error when a click emits on connect (#9321)", async () => {
const page = await newProgrammaticE2EPage();
await page.evaluate(async () => {
const combobox = document.createElement("calcite-combobox");
document.body.click();
document.body.append(combobox);
});
await page.waitForChanges();
});
});
14 changes: 5 additions & 9 deletions packages/calcite-components/src/components/combobox/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ import {
updateMessages,
} from "../../utils/t9n";
import { Scale, SelectionMode, Status } from "../interfaces";
import { XButton, CSS as XButtonCSS } from "../functional/XButton";
import { getIconScale } from "../../utils/component";
import { CSS as XButtonCSS, XButton } from "../functional/XButton";
import { componentOnReady, getIconScale } from "../../utils/component";
import { Validation } from "../functional/Validation";
import { ComboboxMessages } from "./assets/combobox/t9n";
import { ComboboxChildElement, SelectionDisplay } from "./interfaces";
Expand Down Expand Up @@ -343,16 +343,12 @@ export class Combobox
//--------------------------------------------------------------------------

@Listen("click", { target: "document" })
documentClickHandler(event: PointerEvent): void {
if (this.disabled) {
async documentClickHandler(event: PointerEvent): Promise<void> {
if (this.disabled || event.composedPath().includes(this.el)) {
return;
}

const composedPath = event.composedPath();

if (composedPath.includes(this.el) || composedPath.includes(this.referenceEl)) {
return;
}
await componentOnReady(this.el);

if (!this.allowCustomValues && this.textInput.value) {
this.clearInputValue();
Expand Down
Loading