diff --git a/frontend/code/components/pointerEventListener.ts b/frontend/code/components/pointerEventListener.ts index 3f27a464..12f58e9e 100644 --- a/frontend/code/components/pointerEventListener.ts +++ b/frontend/code/components/pointerEventListener.ts @@ -20,7 +20,7 @@ export type PointerEventListenerState = ComponentState & { reportDragMove: boolean; reportDragEnd: boolean; consume_events: boolean; - capture_events: boolean; + event_order: "before-child" | "after-child"; }; const DOUBLE_CLICK_TIMEOUT = 300; @@ -31,7 +31,7 @@ export class PointerEventListenerComponent extends ComponentBase void | null = null; + private _onClickBound: ((e: MouseEvent) => void) | null = null; private _onPointerDownBound: ((e: PointerEvent) => void) | null = null; private _onPointerUpBound: ((e: PointerEvent) => void) | null = null; private _onPointerMoveBound: ((e: PointerEvent) => void) | null = null; @@ -55,19 +55,18 @@ export class PointerEventListenerComponent extends ComponentBase | null { // Convert the pointer type // // Some browsers (e.g. Safari) sometimes have `undefined` as the pointer @@ -394,14 +394,14 @@ export class PointerEventListenerComponent extends ComponentBase( eventName: string, shouldInstall: boolean, - captureEvents: boolean, + eventOrder: "before-child" | "after-child", currentHandler: ((e: T) => void) | null, callbackMethod: (this: PointerEventListenerComponent, e: T) => void ): ((e: T) => void) | null { // Remove existing listener if it exists if (currentHandler !== null) { this.element.removeEventListener(eventName, currentHandler, { - capture: this.state.capture_events, + capture: this.state.event_order === "before-child", }); } @@ -412,7 +412,7 @@ export class PointerEventListenerComponent extends ComponentBase JsonDoc: return { diff --git a/tests/test_frontend/test_pointer_event_listener.py b/tests/test_frontend/test_pointer_event_listener.py index 6f7de0da..c1a31366 100644 --- a/tests/test_frontend/test_pointer_event_listener.py +++ b/tests/test_frontend/test_pointer_event_listener.py @@ -71,12 +71,12 @@ async def test_on_double_press_event( ) @pytest.mark.parametrize("pressed_button", ["left", "middle", "right"]) @pytest.mark.parametrize("consume_events", [True, False]) -@pytest.mark.parametrize("capture_events", [True, False]) +@pytest.mark.parametrize("event_order", ["before-child", "after-child"]) async def test_specific_button_events( event_buttons: t.Sequence[t.Literal["left", "middle", "right"]], pressed_button: t.Literal["left", "middle", "right"], consume_events: bool, - capture_events: bool, + event_order: t.Literal["before-child", "after-child"], ) -> None: down_events: list[rio.PointerEvent] = [] up_events: list[rio.PointerEvent] = [] @@ -103,15 +103,19 @@ async def test_specific_button_events( }, on_pointer_up={button: on_pointer_up for button in event_buttons}, consume_events=consume_events, - capture_events=capture_events, + event_order=event_order, ) async with BrowserClient(build) as client: await client.click(0.5, 0.5, button=pressed_button, sleep=0.5) if pressed_button in event_buttons: - assert len(down_events) == 1 + (capture_events and not consume_events) - assert len(up_events) == 1 + (capture_events and not consume_events) + assert len(down_events) == 1 + ( + event_order == "before-child" and not consume_events + ) + assert len(up_events) == 1 + ( + event_order == "before-child" and not consume_events + ) else: assert len(down_events) == 0 assert len(up_events) == 0