Skip to content

fix(radio-group): support compareWith in deselection, tabindex and handle null values safely - #31590

Open
rudrakshagarwal4200-ai wants to merge 3 commits into
ionic-team:mainfrom
rudrakshagarwal4200-ai:rudrakshagarwal4200-ai-patch-3
Open

rudrakshagarwal4200-ai wants to merge 3 commits into
ionic-team:mainfrom
rudrakshagarwal4200-ai:rudrakshagarwal4200-ai-patch-3

Conversation

@rudrakshagarwal4200-ai

Copy link
Copy Markdown

Description

When using compareWith with property name or custom function on ion-radio-group:

  1. Passing null as the current value threw a TypeError (Cannot read properties of null) in compareOptions when accessing currentValue[compareWith].
  2. In radio-group.tsx, onClick and onKeydown checked newValue !== currentValue using strict reference equality, preventing allowEmptySelection from deselecting an option when values matched by compareWith but were distinct object instances.
  3. setRadioTabindex used strict reference equality (radio.value === value) instead of isOptionSelected(value, radio.value, this.compareWith), causing incorrect roving tabindex focus for object values.

This PR fixes these issues by:

  1. Making property-access safe against null / undefined values in compareOptions and returning false early in isOptionSelected when currentValue is null or undefined.
  2. Using isOptionSelected in onClick and onKeydown to properly support allowEmptySelection deselection with compareWith.
  3. Using isOptionSelected in setRadioTabindex to find the checked radio button.
  4. Adding unit tests in core/src/components/radio-group/test/radio-group.spec.tsx.

Fixes #30560

Enhance comparison logic to handle undefined and null values.
Refactor radio selection logic to use isOptionSelected for better comparison.
Added tests for radio group deselection and null handling.
@vercel

vercel Bot commented Oct 16, 2026

Copy link
Copy Markdown

@rudrakshagarwal4200-ai is attempting to deploy a commit to the Ionic Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the package: core @ionic/core package label Oct 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: radio group compareWith doesn't keep in mind null values + it's not used to check for deselection

1 participant