From 7ea14ae41eb27f2a58952bd27d91ef4c77bb6a0c Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Mon, 6 May 2024 11:15:15 -0700 Subject: [PATCH] fix(radio): persist checked state when items are updated in radio-group (#29457) Issue number: resolves #29442 --------- ## What is the current behavior? The state does not stay consistent when the data used to render the radios are updated. ## What is the new behavior? - 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 ## Other information Dev build: 8.1.1-dev.11714760012.1eab947e --------- Co-authored-by: Sean Perkins <13732623+sean-perkins@users.noreply.github.com> --- core/src/components/radio/radio.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/components/radio/radio.tsx b/core/src/components/radio/radio.tsx index 079f5d52c4..05fdfb0603 100644 --- a/core/src/components/radio/radio.tsx +++ b/core/src/components/radio/radio.tsx @@ -110,6 +110,18 @@ export class Radio implements ComponentInterface { */ @Event() ionBlur!: EventEmitter; + 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) {