Skip to content

Add ElementReference to InputRadio#40828

Merged
MackinnonBuck merged 1 commit into
dotnet:mainfrom
campersau:inputradioelementreference
Mar 23, 2022
Merged

Add ElementReference to InputRadio#40828
MackinnonBuck merged 1 commit into
dotnet:mainfrom
campersau:inputradioelementreference

Conversation

@campersau
Copy link
Copy Markdown
Contributor

Description

Add Element property to InputRadio just like the input fields in #29555
Since InputRadioGroup does not use an actual DOM element I left it out.

protected override void BuildRenderTree(RenderTreeBuilder builder)
{
Debug.Assert(_context != null);
// Note that we must not set IsFixed=true on the CascadingValue, because the mutations to _context
// are what cause the descendant InputRadio components to re-render themselves
builder.OpenComponent<CascadingValue<InputRadioContext>>(0);
builder.AddAttribute(2, "Value", _context);
builder.AddAttribute(3, "ChildContent", ChildContent);
builder.CloseComponent();
}

Fixes #40804

@campersau campersau requested a review from a team as a code owner March 22, 2022 22:12
@ghost ghost added area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member labels Mar 22, 2022
@campersau campersau force-pushed the inputradioelementreference branch from 990f1f0 to 4d28bf0 Compare March 22, 2022 22:19
Copy link
Copy Markdown
Member

@MackinnonBuck MackinnonBuck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great.

I believe the reason we didn't initially support this was because radio buttons were always being re-rendered, causing element references to frequently become invalidated, making them useless (#31610). However, since that was fixed in #40148, it should be safe to accept this change.

Thanks @campersau!

@MackinnonBuck MackinnonBuck merged commit 3803406 into dotnet:main Mar 23, 2022
@ghost ghost added this to the 7.0-preview3 milestone Mar 23, 2022
@campersau campersau deleted the inputradioelementreference branch March 23, 2022 04:20
@dougbu dougbu modified the milestones: 7.0-preview3, 7.0-preview4 Apr 5, 2022
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 community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ElementReference to InputRadioGroup & InputRadio

3 participants