Skip to content

Commit a8286f6

Browse files
authored
fix(all): long press now preserves activated state (#25551)
resolves #25544
1 parent 7ac215b commit a8286f6

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

core/src/utils/tap-click.ts renamed to core/src/utils/tap-click/index.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import type { Config } from '../interface';
2-
3-
import { now, pointerCoord } from './helpers';
1+
import type { Config } from '../../interface';
2+
import { now, pointerCoord } from '../helpers';
43

54
export const startTapClick = (config: Config) => {
65
let lastTouch = -MOUSE_WAIT * 10;
@@ -25,6 +24,11 @@ export const startTapClick = (config: Config) => {
2524
};
2625

2726
const onMouseDown = (ev: MouseEvent) => {
27+
// Ignore right clicks
28+
if (ev.button === 2) {
29+
return;
30+
}
31+
2832
const t = now(ev) - MOUSE_WAIT;
2933
if (lastTouch < t) {
3034
pointerDown(ev);
@@ -38,10 +42,6 @@ export const startTapClick = (config: Config) => {
3842
}
3943
};
4044

41-
const onContextMenu = (ev: MouseEvent) => {
42-
pointerUp(ev);
43-
};
44-
4545
const cancelActive = () => {
4646
clearTimeout(activeDefer);
4747
activeDefer = undefined;
@@ -161,8 +161,6 @@ export const startTapClick = (config: Config) => {
161161

162162
doc.addEventListener('mousedown', onMouseDown, true);
163163
doc.addEventListener('mouseup', onMouseUp, true);
164-
165-
doc.addEventListener('contextmenu', onContextMenu, true);
166164
};
167165

168166
const getActivatableTarget = (ev: UIEvent): any => {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { test } from '@utils/test/playwright';
2+
3+
test.describe('tap click utility', () => {
4+
test('it should apply activated class when clicking element', async ({ page }) => {
5+
await page.setContent(`
6+
<ion-app>
7+
<button class="ion-activatable">Click Me</button>
8+
</ion-app>
9+
`);
10+
11+
const button = page.locator('button');
12+
const box = await button.boundingBox()!;
13+
14+
if (box) {
15+
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
16+
await page.mouse.down();
17+
}
18+
19+
await page.waitForSelector('button.ion-activated');
20+
});
21+
});

0 commit comments

Comments
 (0)