Why Chrome emits PointerEvents and Firefox MouseEvents and which type definition should I use in my code
Asked Answered
S

1

9

I'm somewhat new to typescript and try to add type definitions to all my methods while being as precise as possible.

When I click in Chrome a PointerEvent is emitted. In Firefox a MouseEvent is emitted. I know that PointerEvent extends MouseEvent and according to https://developer.mozilla.org/en-US/docs/Web/API/PointerEvent#browser_compatibility Firefox also supports these.

  1. Why does chrome emit a different event than Firefox
  2. Which type should I use in my event listeners (probably MouseEvent)
  3. and most importantly, how do I determine that if both show something different? (a.k.a is it safe to trust chrome or do I have to consult the documentation?)
Sula answered 7/1, 2022 at 19:42 Comment(0)
P
2

This seems to be a bug in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1675847

And in Safari too: https://bugs.webkit.org/show_bug.cgi?id=218665

According to the specs: https://www.w3.org/TR/uievents/#event-type-click it's supposed to be a PointerEvent

So until these bugs are fixed just use MouseEvent since PointerEvent inherits from MouseEvent (https://www.w3.org/TR/pointerevents3/#pointerevent-interface)

Parsec answered 14/8, 2023 at 15:53 Comment(1)
just want to mention a point of confusion is that the MDN docs specify that click is a MouseEvent. also, it seems dblclick in W3C spec is part of MouseEvent, not PointerEvent..Nonperformance

© 2022 - 2024 — McMap. All rights reserved.