leptos-rs / leptos

Build fast web applications with Rust.
https://leptos.dev
MIT License
16.35k stars 655 forks source link

`contextmenu` event expects a `MouseEvent` but should accept a `PointerEvent` #2748

Open bicarlsen opened 3 months ago

bicarlsen commented 3 months ago

Describe the bug The contextmenu event expects a MouseEvent but MDN states it should accept a PointerEvent.

Leptos Dependencies

leptos = { version = "0.6.13", features = ["nightly", "csr"] }

To Reproduce N/A

Expected behavior N/A

Screenshots N/A

Additional context N/A

gbj commented 3 months ago

From the MDN page you link:

A PointerEvent. Inherits from MouseEvent. ... Note: In earlier versions of the specification the event type for this event was a MouseEvent, and this is still the type passed in Firefox and Safari.

i.e., the spec says PointerEvent, but Firefox, Safari, and (maybe?) older versions of all browsers will give you a MouseEvent. PointerEvent inherits from MouseEvent, so you can use any MouseEvent methods or fields if you're using a browser that gives you a PointerEvent, but you cannot actually assume that you are getting a PointerEvent. Writing code that assumes a PointerEvent will likely fail at runtime on some browsers in a way that is not obvious if you're developing on Chrome, as it will work there.

To me, this suggests that the best course of action is to keep it as a MouseEvent and allow you to cast it to PointerEvent using .dyn_into(), and handle the case where it's actually a MouseEvent however you need to for your application. Thoughts?

bicarlsen commented 3 months ago

Seems good to me. Perhaps it's worth a mention in the docs?