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(action-menu, combobox, dropdown, popover, tooltip): use click instead of pointerdown for click contexts #8943

Merged
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 @@ -11,7 +11,7 @@ import {
} from "@stencil/core";
import { Fragment, VNode } from "@stencil/core/internal";
import { getRoundRobinIndex } from "../../utils/array";
import { focusElement, isPrimaryPointerButton, toAriaBoolean } from "../../utils/dom";
import { focusElement, toAriaBoolean } from "../../utils/dom";
import { EffectivePlacement, LogicalPlacement, OverlayPositioning } from "../../utils/floating-ui";
import { guid } from "../../utils/guid";
import { isActivationKey } from "../../utils/key";
Expand Down Expand Up @@ -222,7 +222,7 @@ export class ActionMenu implements LoadableComponent {
menuButtonEl.text = label;
}

menuButtonEl.addEventListener("pointerdown", this.menuButtonClick);
menuButtonEl.addEventListener("click", this.menuButtonClick);
menuButtonEl.addEventListener("keydown", this.menuButtonKeyDown);
};

Expand All @@ -233,7 +233,7 @@ export class ActionMenu implements LoadableComponent {
return;
}

menuButtonEl.removeEventListener("pointerdown", this.menuButtonClick);
menuButtonEl.removeEventListener("click", this.menuButtonClick);
menuButtonEl.removeEventListener("keydown", this.menuButtonKeyDown);
};

Expand Down Expand Up @@ -341,11 +341,7 @@ export class ActionMenu implements LoadableComponent {
this.setFocus();
};

menuButtonClick = (event: PointerEvent): void => {
if (!isPrimaryPointerButton(event)) {
return;
}

private menuButtonClick = (): void => {
this.toggleOpen();
};

Expand Down
11 changes: 3 additions & 8 deletions packages/calcite-components/src/components/combobox/combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ import {
import { debounce } from "lodash-es";
import { filter } from "../../utils/filter";

import {
getElementWidth,
getTextWidth,
isPrimaryPointerButton,
toAriaBoolean,
} from "../../utils/dom";
import { getElementWidth, getTextWidth, toAriaBoolean } from "../../utils/dom";
import {
connectFloatingUI,
defaultMenuPlacement,
Expand Down Expand Up @@ -321,9 +316,9 @@ export class Combobox
//
//--------------------------------------------------------------------------

@Listen("pointerdown", { target: "document" })
@Listen("click", { target: "document" })
documentClickHandler(event: PointerEvent): void {
if (this.disabled || !isPrimaryPointerButton(event)) {
if (this.disabled) {
return;
}

Expand Down
16 changes: 3 additions & 13 deletions packages/calcite-components/src/components/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ import {
} from "@stencil/core";
import { ItemKeyboardEvent } from "./interfaces";

import {
focusElement,
focusElementInGroup,
isPrimaryPointerButton,
toAriaBoolean,
} from "../../utils/dom";
import { focusElement, focusElementInGroup, toAriaBoolean } from "../../utils/dom";
import {
connectFloatingUI,
defaultMenuPlacement,
Expand Down Expand Up @@ -332,14 +327,9 @@ export class Dropdown
/** Fires when the component is open and animation is complete. */
@Event({ cancelable: false }) calciteDropdownOpen: EventEmitter<void>;

@Listen("pointerdown", { target: "window" })
@Listen("click", { target: "window" })
closeCalciteDropdownOnClick(event: PointerEvent): void {
if (
this.disabled ||
!isPrimaryPointerButton(event) ||
!this.open ||
event.composedPath().includes(this.el)
) {
if (this.disabled || !this.open || event.composedPath().includes(this.el)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isPrimaryPointerButton } from "../../utils/dom";
import { ReferenceElement } from "../../utils/floating-ui";
import { isActivationKey } from "../../utils/key";

Expand Down Expand Up @@ -85,18 +84,16 @@ export default class PopoverManager {
};

private clickHandler = (event: PointerEvent): void => {
if (isPrimaryPointerButton(event)) {
this.togglePopovers(event);
}
this.togglePopovers(event);
};

private addListeners(): void {
window.addEventListener("pointerdown", this.clickHandler, { capture: true });
window.addEventListener("click", this.clickHandler, { capture: true });
window.addEventListener("keydown", this.keyHandler, { capture: true });
}

private removeListeners(): void {
window.removeEventListener("pointerdown", this.clickHandler, { capture: true });
window.removeEventListener("click", this.clickHandler, { capture: true });
window.removeEventListener("keydown", this.keyHandler, { capture: true });
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getShadowRootNode, isPrimaryPointerButton } from "../../utils/dom";
import { getShadowRootNode } from "../../utils/dom";
import { ReferenceElement } from "../../utils/floating-ui";
import { TOOLTIP_OPEN_DELAY_MS, TOOLTIP_CLOSE_DELAY_MS } from "./resources";
import { getEffectiveReferenceElement } from "./utils";
Expand Down Expand Up @@ -119,11 +119,7 @@ export default class TooltipManager {
}
};

private pointerDownHandler = (event: PointerEvent): void => {
if (!isPrimaryPointerButton(event)) {
return;
}

private clickHandler = (event: PointerEvent): void => {
const clickedTooltip = this.queryTooltip(event.composedPath());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we change to MouseEvent for consistency?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May apply to other places. Doesn't really matter much since PointerEvent extends MouseEvent.

I also notice some other places using onPointerUp/onPointerDown or using PointerEvent typing for click events.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we search and eliminate the util function isPrimaryPointerButton?

Copy link
Member Author

@jcfranco jcfranco Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we change to MouseEvent for consistency?

I think for our purposes, we can use PointerEvent as it matches the latest spec changes. Worth noting that Firefox and Safari haven't updated yet (see web platform tests).

I also notice some other places using onPointerUp/onPointerDown or using PointerEvent typing for click events.

Do you recall where? I may have missed some, but I updated the places where pointerdown events were being treated as a click. I think isPrimaryPointerButton is still useful. E.g., color-picker's color field and sliders depend on the primary pointer's up and down events.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you spot the ones I missed, I can update them in a follow-up PR.


this.clickedTooltip = clickedTooltip;
Expand Down Expand Up @@ -155,15 +151,15 @@ export default class TooltipManager {
private addListeners(): void {
window.addEventListener("keydown", this.keyDownHandler, { capture: true });
window.addEventListener("pointermove", this.pointerMoveHandler, { capture: true });
window.addEventListener("pointerdown", this.pointerDownHandler, { capture: true });
window.addEventListener("click", this.clickHandler, { capture: true });
window.addEventListener("focusin", this.focusInHandler, { capture: true });
window.addEventListener("focusout", this.focusOutHandler, { capture: true });
}

private removeListeners(): void {
window.removeEventListener("keydown", this.keyDownHandler, { capture: true });
window.removeEventListener("pointermove", this.pointerMoveHandler, { capture: true });
window.removeEventListener("pointerdown", this.pointerDownHandler, { capture: true });
window.removeEventListener("click", this.clickHandler, { capture: true });
window.removeEventListener("focusin", this.focusInHandler, { capture: true });
window.removeEventListener("focusout", this.focusOutHandler, { capture: true });
}
Expand Down
Loading