-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Fix IdAttributeValue generation in interactive mode #65263
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
base: main
Are you sure you want to change the base?
Fix IdAttributeValue generation in interactive mode #65263
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a bug where the id attribute was not being generated for input components in interactive mode (e.g., Blazor WebAssembly or interactive render modes). The id attribute is essential for Label/Input association to work correctly, even when the name attribute is not generated.
Changes:
- Refactored field name generation logic into a new
GetFieldName()method inInputBase<TValue> - Modified
IdAttributeValueto independently generate the field name whenNameAttributeValuereturns empty (interactive mode) - Added tests to verify
idattribute generation in interactive scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Components/Web/src/Forms/InputBase.cs | Extracted GetFieldName() method and updated IdAttributeValue to fall back to generating field name independently when needed for interactive mode |
| src/Components/Web/test/Forms/InputTextTest.cs | Added two new tests to verify id attribute generation in interactive mode scenarios |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Background
Previously,
IdAttributeValuerelied only onNameAttributeValuewhich returns empty in interactive mode. Now it falls back to generating the field name directly when needed.When implementing #64821 we missed the point that
NameAttributeValueis not always generated.While it makes sense for
nameto be generated only in SSR for form submission (interactivity relies on binding there), we needidto support the Lable/input association regardless of render mode.Details
The generation logic common for name and id got moved to a separate method.
Follow up for #64821 (comment).