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

Current Blazor event handling fails for some CustomElement scenarios #59602

Closed
1 task done
MarkStega opened this issue Dec 22, 2024 · 2 comments
Closed
1 task done

Current Blazor event handling fails for some CustomElement scenarios #59602

MarkStega opened this issue Dec 22, 2024 · 2 comments
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved

Comments

@MarkStega
Copy link

MarkStega commented Dec 22, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am using a CustomElement in Blazor that implements checkbox functionality. The component reports the state of checked/unchecked in an identical fashion as a native <input type="checked"> The determination of a checkbox in RenderingEventForDotNet only works for native input controls.

This has been discussed as early as the late stages of .Net 5 with some suggestions and even an incomplete PR
IsCheckbox based on role and not only for input DOM elements #27030
[Blazor] Cannot bind custom checkbox element's checked value

But here we are at .Net 9 and no relief...

Describe the solution you'd like

I posit that there are always going to be some edge cases where mapping the Value can't get handled with addition of a role or other methodology and that other elements of the event may be required.

I can certainly add my own event listener on the custom element and call back into Blazor with the checked state. This works but I consider it ugly.

Slightly less ugly (but I guess it is in the eye of the beholder) I simply created a custom event that grabs the checked attribute. Again, it works, but still not really elegant.

I propose standard events have two maps, the current simplified map so oninput, onchange, etc. all work as they do now and a second set that returns the complete event. These could be named as ondomchange, ondominput or onnativechange, onnativeinput. There would have to be corresponding types in C# that reflect the TypeScript definitions found in lib.dom.d.ts

The goal is just to make it easier in Blazor to use CustomElements that may not be wrapping a native element.

@SteveSandersonMS

Additional context

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Dec 22, 2024
@javiercn
Copy link
Member

javiercn commented Jan 7, 2025

@MarkStega thanks for contacting us.

I propose standard events have two maps, the current simplified map so oninput, onchange, etc. all work as they do now and a second set that returns the complete event. These could be named as ondomchange, ondominput or onnativechange, onnativeinput. There would have to be corresponding types in C# that reflect the TypeScript definitions found in lib.dom.d.ts

It's not clear what you are suggesting, but we would be incredibly wary of adding a second set of events to represent the same/similar concepts. We didn't originally expose all the event details because it is in general not possible to serialize all the information in the event.

We could change the code in JS to detect "role=checkbox" but for custom elements in general, we would expect the developer to define the events. If you need more information from the JS side, custom events is the right way to handle this scenario.

@javiercn javiercn added question ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. labels Jan 7, 2025
Copy link
Contributor

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved
Projects
None yet
Development

No branches or pull requests

2 participants