Skip to content

Can't cancel event propagation in Yew 0.20 #3041

Open
@cecton

Description

@cecton

Problem

Relevant code: https://github.com/yozhgoor/yewprint/blob/update-dependencies/src/tree.rs#L297-L317

In Yewprint I have a <Tree/> component which I replicated from the JS code of Blueprint. As you can see here, the onclick event is bound on a div and on a child node:

<div
    class="bp3-tree-node-content"
    style={content_style}
    onclick={self.handler_click.clone()}
>
		// ...
                <Icon
                    class={classes!(class.to_string())}
                    icon={IconName::ChevronRight}
                    onclick={self.handler_caret_click.clone()}
                />

The way it is normally handled (by Blueprint and thus by Yewprint) is to stop the propagation of the click event if the click event occurred on the caret. As you can see here:

match msg {
    TreeNodeMessage::CaretClick(event) => {
        if ctx.props().is_expanded {
            if let Some(on_collapse) = ctx.props().on_collapse.as_ref() {
                event.stop_propagation();                                    <--- here
                on_collapse.emit((ctx.props().node_id.clone(), event));
            }
        } else if let Some(on_expand) = ctx.props().on_expand.as_ref() {
            event.stop_propagation();                                        <--- here
            on_expand.emit((ctx.props().node_id.clone(), event));
        }
    }
    TreeNodeMessage::Click(event) => {
        if let Some(onclick) = ctx.props().onclick.as_ref() {
            onclick.emit((ctx.props().node_id.clone(), event));
        }
    }
}

This is in par with Blueprint's code: https://github.com/palantir/blueprint/blob/a8b99210bfb1510d9164f9a59a5103d555c75447/packages/core/src/components/tree/treeNode.tsx#L188

This is working properly with Yew 0.19 but it is somehow broken in Yew 0.20.

I'm not sure what could be possibly the cause here or if it should be considered as a bug at all. If someone could give me a few pointers...

Steps To Reproduce

  1. Clone the source code of yozhgoor's fork: git clone https://github.com/yozhgoor/yewprint.git
  2. Change dir: cd yewprint
  3. Checkout to the commit where the issue occurs: git checkout --detach 4fc68f4b
  4. Run the dev server: cargo xtask start (no build tool required to install)
  5. Connect to the dev server: http://localhost:8000/tree

You can do the same with Yew 0.19 by cloning https://github.com/yewprint/yewprint.git instead.

Expected behavior

When clicking on the caret, the menu item should not highlight.

Actual behavior

When clicking on the caret, the menu item highlight.

Screenshots

screenshot2

Environment:

  • Yew version: 0.20
  • Rust version: 1.65.0
  • Target: wasm32-unknown-unknown
  • Build tool: xtask-wasm (nothing to install)
  • OS: Linux
  • Browser and version, if relevant: Firefox 107.0.1

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions