Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@onchange not bubbling in Blazor #34758

Closed
eeegs opened this issue Jul 27, 2021 · 7 comments
Closed

@onchange not bubbling in Blazor #34758

eeegs opened this issue Jul 27, 2021 · 7 comments
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Pillar: Technical Debt

Comments

@eeegs
Copy link

eeegs commented Jul 27, 2021

Describe the bug

When applying an event handler to a parent element, the on change from child controls does not bubble up. It does bubble up in reality as the framework registers document level event handlers. But whatever those handler do to distribute the event into underlying code does not allow for passing the event to non-input control types - that how I see it anyway.

This is not how the event is meant to work. I should be able to listen on a parent element for a change event from a child.

If you put the handler in the code below on the input, then all is fine. But that's not the thing I'm trying to do.

To Reproduce

Start with a clean WASM project, and change the Index.razor to this:

page "/"

<div @onchange="Fred">
    <input />
</div>

@changed

@code
{

    string changed = "Nope!";

    void Fred(ChangeEventArgs args)
    {
        changed = "yep!!";
    }
}

Exceptions (if any)

None seen

Further technical details

  • Ver 5.08
@javiercn javiercn added the area-blazor Includes: Blazor, Razor Components label Jul 27, 2021
@eeegs
Copy link
Author

eeegs commented Jul 27, 2021

This file aspnetcore/src/Components/Web.JS/src/Rendering/Events/EventDelegator.ts has, in line 5, (see below) a const declaring change (and other events) as a nonBubblingEvent. However the HTML specification would indicate that abort, change, error, reset, scroll and submit from your const definition are meant to bubble.

It looks like after you scan the up the tree you then discard any found candidate in line 171: candidateElement = (eventIsNonBubbling || stopPropagationWasRequested) ? null : candidateElement.parentElement;

I contest your list of nonBubbling events is incorrect.

Offending code: aspnetcore/src/Components/Web.JS/src/Rendering/Events/EventDelegator.ts (line 5)

const nonBubblingEvents = toLookup([
  'abort',
  'blur',
  'change',
  'error',
  'focus',
  'load',
  'loadend',
  'loadstart',
  'mouseenter',
  'mouseleave',
  'progress',
  'reset',
  'scroll',
  'submit',
  'unload',
  'toggle',
  'DOMNodeInsertedIntoDocument',
  'DOMNodeRemovedFromDocument',
]);

@mkArtakMSFT mkArtakMSFT added the bug This issue describes a behavior which is not expected - a bug. label Jul 27, 2021
@mkArtakMSFT mkArtakMSFT added this to the Backlog milestone Jul 27, 2021
@ghost
Copy link

ghost commented Jul 27, 2021

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@eeegs
Copy link
Author

eeegs commented Aug 10, 2022

Any movement on this? It should be simple fix.

@eeegs
Copy link
Author

eeegs commented Sep 30, 2022

So who knows where the rubber duck comes from? Oh, and will this get fixed?

@mkArtakMSFT
Copy link
Member

@SteveSandersonMS any thoughts regarding this one?

@halter73
Copy link
Member

Here was the original change: dotnet/blazor#722

onchange does bubble though, it's just not cancellable. See:

https://en.wikipedia.org/wiki/DOM_event#Events
https://stackoverflow.com/questions/5574207/html-dom-which-events-do-not-bubble

@mkArtakMSFT mkArtakMSFT closed this as not planned Won't fix, can't repro, duplicate, stale Dec 22, 2023
@SteveSandersonMS
Copy link
Member

@mkArtakMSFT Yep, would be good to make this behave the same as a native click event.

@ghost ghost locked as resolved and limited conversation to collaborators Feb 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. Pillar: Technical Debt
Projects
None yet
Development

No branches or pull requests

6 participants
@halter73 @SteveSandersonMS @javiercn @mkArtakMSFT @eeegs and others