Skip to content

Cannot call prevent_default on WheelEvents #2110

@NickHu

Description

@NickHu

Problem
No way to call prevent_default() for WheelEvent.
Steps To Reproduce
Steps to reproduce the behavior:

  1. Apply
    diff --git a/examples/counter/src/main.rs b/examples/counter/src/main.rs
    index 14242db1..20393c6c 100644
    --- a/examples/counter/src/main.rs
    +++ b/examples/counter/src/main.rs
    @@ -57,7 +57,10 @@ impl Component for Model {
                     </div>
     
                     // Display the current value of the counter
    -                <p class="counter">
    +                <p class="counter" onwheel={ctx.link().callback_with_passive(Some(false), |e: yew::WheelEvent| {
    +                    e.prevent_default();
    +                    Msg::Increment
    +                })}>
                         { self.value }
                     </p>
  2. Run the counter example
  3. Scroll on the counter to increment it
  4. Observe console errors saying how prevent default failed due to listener being passive

I suspect that this is caused by #1542 having been merged (it worked previously).

Note that I explicitly set the listener to be not passive by using callback_with_passive, but this seems to have no effect (regardless of what value I choose for its first argument). It also seems to be impossible to get explicitly non/passive listeners via Callback::from.

This not ideal because, on Firefox, ALT + mouse scrolling navigates back/forwards.

Expected behavior
prevent_default() works.

Environment:

  • Yew version: current master 77b46bf
  • Rust version: 1.55

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-yewArea: The main yew cratebug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions