Skip to content

Commit

Permalink
feat: Ignore touch on more interactive elements
Browse files Browse the repository at this point in the history
Fixes #1654.
  • Loading branch information
StarScape committed Mar 20, 2024
1 parent cbb94e3 commit 455d21d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import {
ContentConfigParams,
} from '../common/content-config-params';
import { CopyKeys, CopyType } from '../common/copy-keys';
import { isEditableNode } from '../utils/dom-utils';
import { isEditableNode, isInteractiveElement } from '../utils/dom-utils';
import {
addMarginToPoint,
getMarginAroundPoint,
Expand Down Expand Up @@ -301,10 +301,7 @@ export class ContentHandler {

this.touchClickTracker.onTouchClick = (event: MouseEvent) => {
// Ignore clicks on interactive elements
if (
event.target instanceof HTMLAnchorElement ||
event.target instanceof HTMLButtonElement
) {
if (event.target instanceof Node && isInteractiveElement(event.target)) {
return;
}

Expand Down
19 changes: 19 additions & 0 deletions src/utils/dom-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,25 @@ export function isEditableNode(node: Node | null): boolean {
return isTextInputNode(node) || isContentEditableNode(node);
}

/**
* Tests whether an element is 'interactive', i.e. an element
* that we should not do lookups on when tapped on mobile.
*/
export function isInteractiveElement(node: Node | null) {
return (
isContentEditableNode(node) ||
(isElement(node) &&
(node.tagName === 'A' ||
node.tagName === 'BUTTON' ||
node.tagName === 'INPUT' ||
node.tagName === 'TEXTAREA' ||
node.tagName === 'SELECT' ||
node.tagName === 'DATALIST' ||
node.tagName === 'OPTGROUP' ||
node.tagName === 'OPTION'))
);
}

export interface Focusable {
focus(): void;
}
Expand Down

0 comments on commit 455d21d

Please sign in to comment.