Skip to content

[Blazor] Blazor InputRadio is broken by IHandleEvent #53245

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

Merged
merged 4 commits into from
Jan 10, 2024

Conversation

javiercn
Copy link
Member

@javiercn javiercn commented Jan 9, 2024

Will add an E2E test for this. But the TL;DR is as follows:

The CurrentValue property in the context was being initialized the first time, but was not being updated afterwards even though it changed on the InputRadioGroup. That meant that InputRadio components would not see the value immediately as part of the first render.

This was working on other scenarios because the default implementation in ComponentBase will trigger a re-render of the parent component, which in turn will trigger a re-render of the InputGroup component (since it receives a render fragment) and at that point, the component would update the parameter and the re-render of the individual InputRadio elements would work.

When someone implements IHandleEvent, that doesn't necessarily happen, hence the reason for the bug. The fix is to avoid updating the value in the context as a separate step and instead making the context reflect the value from the input.

@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Jan 9, 2024
@javiercn javiercn marked this pull request as ready for review January 9, 2024 18:28
@javiercn javiercn requested a review from a team as a code owner January 9, 2024 18:28
@SteveSandersonMS
Copy link
Member

Looks good!

@javiercn javiercn force-pushed the javiercn/issue-52069 branch from 219459d to 80e6046 Compare January 10, 2024 13:14
@javiercn javiercn merged commit 6cfc445 into main Jan 10, 2024
@javiercn javiercn deleted the javiercn/issue-52069 branch January 10, 2024 15:39
@ghost ghost added this to the 9.0-preview1 milestone Jan 10, 2024
@javiercn
Copy link
Member Author

/backport to release/8.0

Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/aspnetcore/actions/runs/7477275680

mkArtakMSFT pushed a commit that referenced this pull request Jan 16, 2024
…53270)

Backport of #53245 to release/8.0

/cc @javiercn

# [Blazor] Blazor InputRadio is broken by IHandleEvent

Update `InputRadioContext` to get the `CurrentValue` directly from the `InputRadioGroup` rather than using a copy that needs to be updated.

## Description

Input radio groups did not update their values correctly when the component that used them implemented IHandleEvent. When the user clicked on the input radio, the value would not be updated in the UI.

Fixes #52069

## Customer Impact

Input radio elements are not correctly updated when the component that uses them implements IHandleEvent.

## Regression?

- [X] Yes
- [ ] No

7.0

## Risk

- [ ] High
- [ ] Medium
- [X] Low

[Justify the selection above]

## Verification

- [ ] Manual (required)
- [X] Automated

## Packaging changes reviewed?

- [ ] Yes
- [ ] No
- [x] N/A

----

## When servicing release/2.1

- [ ] Make necessary changes in eng/PatchConfig.props

---------

Co-authored-by: jacalvar <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants