fix(radio): persist checked state when items are updated in radio-group (#29457)

Issue number: resolves #29442

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

The state does not stay consistent when the data used to render the
radios are updated.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- The state updates after the component loads, this allows the value to
be set after the radio is rendered.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!--
  If this introduces a breaking change:
1. Describe the impact and migration path for existing applications
below.
  2. Update the BREAKING.md file with the breaking change.
3. Add "BREAKING CHANGE: [...]" to the commit description when merging.
See
https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer
for more information.
-->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Dev build: 8.1.1-dev.11714760012.1eab947e

---------

Co-authored-by: Sean Perkins <13732623+sean-perkins@users.noreply.github.com>
This commit is contained in:
Maria Hutt
2024-05-06 11:15:15 -07:00
committed by GitHub
parent a57ca8d5b4
commit 7ea14ae41e

View File

@ -110,6 +110,18 @@ export class Radio implements ComponentInterface {
*/
@Event() ionBlur!: EventEmitter<void>;
componentDidLoad() {
/**
* The value may be `undefined` if it
* gets set before the radio is
* rendered. This ensures that the radio
* is checked if the value matches. This
* happens most often when Angular is
* rendering the radio.
*/
this.updateState();
}
/** @internal */
@Method()
async setFocus(ev: globalThis.Event) {