Skip to content

[Blazor] Cannot bind custom checkbox element's checked value #24916

@CuddleBunny

Description

@CuddleBunny

Describe the bug

Cannot bind custom checkbox element's checked value.

I am using the new FAST web components in a Blazor server side application and trying to bind the checkbox component any way I can, referencing <input type="checkbox" />:

<!-- Works! -->
<input type="checkbox" @bind="MyBool" />

<!-- Does not work... -->
<fast-checkbox @bind-checked="MyBool" @bind-checked:event="onchange"></fast-checkbox>
<fast-checkbox checked="@MyBool" @onchange="@((ChangeEventArgs e) => ViewModel.AcceptTerms = (bool)e.Value"></fast-checkbox>

I know the values themselves are binding because changing the native input will cause the fast components to change to match. The problem seems to lie within the event. The event mapping code has a check built in specifically for checkboxes which causes the change event value to fall back to element.value, in this case e.Value is always "on".

Rather than making an exception for checkboxes, could we simply always include both value and checked in ChangeEventArgs to match the JavaScript behavior? If this approach is acceptable I will open a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pillar: Technical Debtaffected-mostThis issue impacts most of the customersarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.component ecosystemIndicates an issue which also has impact on 3rd party component ecosystemfeature-blazor-component-modelAny feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc)severity-majorThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions