fix shape interactions from scrolling on safari

This commit is contained in:
“chrisshank” 2024-12-24 09:41:41 -08:00
parent 570edec9ba
commit b3b348bc6b
2 changed files with 11 additions and 12 deletions

View File

@ -105,7 +105,7 @@ const styles = css`
border-radius: 2px; border-radius: 2px;
@media (any-pointer: coarse) { @media (any-pointer: coarse) {
width: 13px; width: 15px;
} }
} }
@ -114,7 +114,7 @@ const styles = css`
width: 16px; width: 16px;
@media (any-pointer: coarse) { @media (any-pointer: coarse) {
width: 20px; width: 25px;
} }
} }
@ -266,6 +266,7 @@ export class FolkShape extends FolkElement {
const root = super.createRenderRoot(); const root = super.createRenderRoot();
this.addEventListener('pointerdown', this); this.addEventListener('pointerdown', this);
this.addEventListener('touchmove', this, { passive: false });
this.addEventListener('keydown', this); this.addEventListener('keydown', this);
// Ideally we would creating these lazily on first focus, but the resize handlers need to be around for delegate focus to work. // Ideally we would creating these lazily on first focus, but the resize handlers need to be around for delegate focus to work.
@ -313,7 +314,13 @@ export class FolkShape extends FolkElement {
return this.#readonlyRect; return this.#readonlyRect;
} }
handleEvent(event: PointerEvent | KeyboardEvent) { handleEvent(event: PointerEvent | KeyboardEvent | TouchEvent) {
// prevent IOS Safari from scrolling when a shape is interacted with.
if (event instanceof TouchEvent) {
event.preventDefault();
return;
}
const focusedElement = (this.renderRoot as ShadowRoot).activeElement as HTMLElement | null; const focusedElement = (this.renderRoot as ShadowRoot).activeElement as HTMLElement | null;
const target = event.composedPath()[0] as HTMLElement; const target = event.composedPath()[0] as HTMLElement;
let handle: Handle | null = null; let handle: Handle | null = null;

View File

@ -73,14 +73,6 @@ rotation: from.x"
import '@labs/standalone/folk-event-propagator.ts'; import '@labs/standalone/folk-event-propagator.ts';
import { Gizmos } from '@lib/folk-gizmos'; import { Gizmos } from '@lib/folk-gizmos';
document.addEventListener(
'touchmove',
(event) => {
event.preventDefault();
},
{ passive: false },
);
const ropes = Array.from(document.querySelectorAll('folk-event-propagator')); const ropes = Array.from(document.querySelectorAll('folk-event-propagator'));
let orientationEvent; let orientationEvent;