Make InputRadioGroup preserve child elements#40148
Merged
Merged
Conversation
| internal static class AttributeUtilities | ||
| { | ||
| public static string CombineClassNames(IReadOnlyDictionary<string, object>? additionalAttributes, string classNames) | ||
| public static string? CombineClassNames(IReadOnlyDictionary<string, object>? additionalAttributes, string? classNames) |
Member
Author
There was a problem hiding this comment.
The nullability changes here and below are just because this code actually does work fine with a null classNames, and the new code benefits by not having to do a ?? string.Empty.
| { | ||
| var groupName = !string.IsNullOrEmpty(Name) ? Name : _defaultGroupName; | ||
| var fieldClass = EditContext?.FieldCssClass(FieldIdentifier) ?? string.Empty; | ||
| var changeEventCallback = EventCallback.Factory.CreateBinder<string?>(this, __value => CurrentValueAsString = __value, CurrentValueAsString); |
Member
Author
There was a problem hiding this comment.
We can also avoid creating a new delegate here on every render.
pranavkm
reviewed
Feb 11, 2022
Contributor
|
@SteveSandersonMS I prefer this solution over mine, as it's cleaner aspnetcore/src/Components/Components/src/CascadingValue.cs Lines 125 to 128 in 6f5aeb7 Always good to learn something new. All concerns addressed in my PR are also addressed here |
javiercn
approved these changes
Feb 14, 2022
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #31610 and #39145, and supersedes #39208
@MariovanZeist - thanks so much for contributing #39208. I hope you don't mind me coming up with a slightly different solution in this PR. The reasons I wanted to do it differently are:
IsFixedis false, so simply by removing theIsFixed=truewe get the desired behavior without needing a new mechanism.@keyto recreate the entire child hierarchy every time, whereas now it retains the child hierarchy and just triggers the appropriate re-rendering.The fix could have been reduced to removing these two lines from
InputRadioGroup:However, in this PR I also chose to reduce allocations by not creating a new
InputRadioContexton every render, and instead retaining the existing instance and mutating it in place. It's not particularly complicated to do that but did add quite a few extra changes to the PR diff.As far as I know, this produces the desired behavior and works as well as the PR at #39208. I verified that it also passes the E2E tests supplied in that PR. But @MariovanZeist, if you have any concerns that the approach here doesn't meet your goals, please let me know!