Skip to content

fix(radio-group): handle null values in compareOptions and use compareWith for deselection - #31585

Open
rudrakshagarwal4200-ai wants to merge 3 commits into
ionic-team:mainfrom
rudrakshagarwal4200-ai:rudrakshagarwal4200-ai-patch-1fix/radio-group-compare-with-null-30560
Open

rudrakshagarwal4200-ai wants to merge 3 commits into
ionic-team:mainfrom
rudrakshagarwal4200-ai:rudrakshagarwal4200-ai-patch-1fix/radio-group-compare-with-null-30560

Conversation

@rudrakshagarwal4200-ai

Copy link
Copy Markdown

Fixes #30560.

Description of Change

  1. Null-safe compareOptions: When compareWith is specified as a string property name, accessing properties on null or undefined values threw a TypeError: Cannot read properties of null (reading ...). This occurs in forms where the model value is initially null or reset to null. Added a null/undefined check so currentValue == null || compareValue == null safely returns currentValue === compareValue.
  2. compareWith equality for deselection and tabindex in radio-group:
    • onClick: Previously checked newValue !== currentValue. When object values are used with compareWith, different object references were never seen as equal, causing allowEmptySelection deselection to fail and re-selecting instead. Now uses isOptionSelected(currentValue, newValue, this.compareWith).
    • onKeydown: Space key check for deselection now uses isOptionSelected(this.value, current.value, this.compareWith).
    • setRadioTabindex: Uses isOptionSelected(value, radio.value, this.compareWith) to correctly locate the active radio button for object values.
  3. Added e2e tests covering allowEmptySelection with compareWith object values and verifying compareWith does not throw when value is null.

…areOptions against null values

Add null checks for currentValue and compareValue in compareWith function.
Add tests for radio group behavior with empty selection and null values.
@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