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

Blazor [EditorRequired] is a good move but can we get a [EditorBindRequired] as well #61032

Closed
1 task done
ScottProgrammer opened this issue Mar 20, 2025 · 1 comment
Closed
1 task done
Labels
area-blazor Includes: Blazor, Razor Components

Comments

@ScottProgrammer
Copy link

ScottProgrammer commented Mar 20, 2025

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.

If I design a component to bind a property eg
<component @bind-Value="_value" />
there is nothing to enforce the bind is used
if I do

[Parameter]
[EditorRequired]
public int Value { get; set; }
[Parameter]
[EditorRequired]
public EventCallback<int> ValueChanged { get; set; }

it sort of does it but you need to specify them separately
<component Value="_value" ValueChanged="@((e) => _value = e)" />

using
<component @bind-Value="_value" />
show the warning "Component 'Component' expects a value for the parameter 'ValueChanged', but a value may not have been provided."

Describe the solution you'd like

it would be great if there was an [EditorBindRequired] attribute
so adding
<component Value="_value" />
gave a warning saying the "Component 'Component' expects the value parameter to be bound",
which would help anyone using my component to know this at design time and use the proper
<component @bind-Value="_value" />

Additional context

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Mar 20, 2025
@javiercn
Copy link
Member

@ScottProgrammer thanks for contacting us.

This is not a direction we plan to go in. @bind is considered syntactic sugar from the framework perspective and it's something we want to keep that way. If you apply [EditorRequired] to the Value changed it should be enough to "force" the binding syntax.

@javiercn javiercn closed this as not planned Won't fix, can't repro, duplicate, stale Mar 20, 2025
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
Projects
None yet
Development

No branches or pull requests

2 participants