fix(all): long press now preserves activated state (#25551)

resolves #25544
This commit is contained in:
Liam DeBeasi
2022-06-30 09:56:57 -04:00
committed by GitHub
parent 7ac215b2c8
commit a8286f6e42
2 changed files with 28 additions and 9 deletions

View File

@ -1,6 +1,5 @@
import type { Config } from '../interface'; import type { Config } from '../../interface';
import { now, pointerCoord } from '../helpers';
import { now, pointerCoord } from './helpers';
export const startTapClick = (config: Config) => { export const startTapClick = (config: Config) => {
let lastTouch = -MOUSE_WAIT * 10; let lastTouch = -MOUSE_WAIT * 10;
@ -25,6 +24,11 @@ export const startTapClick = (config: Config) => {
}; };
const onMouseDown = (ev: MouseEvent) => { const onMouseDown = (ev: MouseEvent) => {
// Ignore right clicks
if (ev.button === 2) {
return;
}
const t = now(ev) - MOUSE_WAIT; const t = now(ev) - MOUSE_WAIT;
if (lastTouch < t) { if (lastTouch < t) {
pointerDown(ev); pointerDown(ev);
@ -38,10 +42,6 @@ export const startTapClick = (config: Config) => {
} }
}; };
const onContextMenu = (ev: MouseEvent) => {
pointerUp(ev);
};
const cancelActive = () => { const cancelActive = () => {
clearTimeout(activeDefer); clearTimeout(activeDefer);
activeDefer = undefined; activeDefer = undefined;
@ -161,8 +161,6 @@ export const startTapClick = (config: Config) => {
doc.addEventListener('mousedown', onMouseDown, true); doc.addEventListener('mousedown', onMouseDown, true);
doc.addEventListener('mouseup', onMouseUp, true); doc.addEventListener('mouseup', onMouseUp, true);
doc.addEventListener('contextmenu', onContextMenu, true);
}; };
const getActivatableTarget = (ev: UIEvent): any => { const getActivatableTarget = (ev: UIEvent): any => {

View File

@ -0,0 +1,21 @@
import { test } from '@utils/test/playwright';
test.describe('tap click utility', () => {
test('it should apply activated class when clicking element', async ({ page }) => {
await page.setContent(`
<ion-app>
<button class="ion-activatable">Click Me</button>
</ion-app>
`);
const button = page.locator('button');
const box = await button.boundingBox()!;
if (box) {
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
await page.mouse.down();
}
await page.waitForSelector('button.ion-activated');
});
});