Skip to content

fix(react,angular): give each ChoicePicker instance a unique radio group name - #2449

Merged
josemontespg merged 4 commits into
a2ui-project:mainfrom
retz8:fix/choicepicker-radio-group-collision
Sep 1, 2026
Merged

josemontespg merged 4 commits into
a2ui-project:mainfrom
retz8:fix/choicepicker-radio-group-collision

Conversation

@retz8

@retz8 retz8 commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

ChoicePicker derived its radio group name from the A2UI component id, which is only surface-scoped, while HTML radio names are document-scoped. Two surfaces rendered in one document with same-id pickers (a legal and typical payload, e.g.
both LLM-generated as picker) merged into a single document-wide radio group. A picker could permanently fail to display its own selection while its data model updated, and radio arrow-key navigation crossed surfaces and changed the other surface's selection and data model.

fix #2447

Fix

The radio group name no longer comes from the component id alone (all radios within one picker still share it):

  • React (ChoicePicker.tsx): React.useId() — unique per rendered instance, and the same pattern the sibling components (Slider, TextField, CheckBox, DateTimeInput) already use for their instance-unique label/input ids.
  • Angular (choice-picker.component.ts): a computed name combining surface id, component id, and sanitized data context path (a2ui-choice-<surfaceId>-<componentId>-<path>). The derivation is deterministic (SSR-friendly), and the path component disambiguates instances stamped from a list template within one surface. Checkboxes no longer receive a name (bound via attr.name so the attribute is removed entirely, matching React).
  • Lit is unaffected — its radios carry no name.

An alternative would be to qualify the name with the surface id (${surfaceId}-${componentId}), but that still collides whenever the same surface is rendered twice in one document (previews, debug panes, side-by-side views), so the instance-unique id was chosen. This covers both cases and needs no API changes!

Testing

Regression tests in both renderers render two pickers with the same component id into one document and assert their radio groups are disjoint (and, in React, that selections stay independent per surface). Both tests were verified to fail against the unfixed code and pass with the fix. A further Angular spec asserts checkboxes carry no name attribute.

  • React: yarn workspace @a2ui/react test:unit — 475/475 pass.
  • Angular: yarn workspace @a2ui/angular test:unit — 259/259 pass.
  • Manually verified in Chrome, both pickers now show their own selection simultaneously, and arrow-key navigation stays inside the focused picker (GIFs below).

BEFORE
choicepicker_radio_collision

AFTER
choicepicker_radio_collision_fixed

Pre-launch Checklist

One time:

For this PR:

  • I have updated the relevant CHANGELOG.md file.
  • I updated/added relevant documentation.
  • My code changes (if any) have tests.
  • If my branch is on a fork, I have verified that scripts/e2e_test.sh passes.

…oup name

ChoicePicker derived its radio group name from the A2UI component id,
which is only surface-scoped, while HTML radio names are
document-scoped. Two surfaces rendered in one document with same-id
pickers (a legal and typical payload, e.g. both LLM-generated as
'picker') merged into a single document-wide radio group: a picker
could permanently fail to display its own selection while its data
model updated, and radio arrow-key navigation crossed surfaces and
changed the other surface's selection and data model.

React: use React.useId() for the group name, the pattern the sibling
components already use for instance-unique label/input ids. Angular:
a module-level counter. Lit is unaffected (its radios carry no name).
Regression tests render two same-id pickers into one document and
assert their groups are disjoint and their selections independent.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request resolves an issue where ChoicePicker radio groups collide across surfaces by ensuring that the radio group name is unique per rendered instance rather than derived from the surface-scoped component ID. This fix is implemented for both Angular and React renderers, with accompanying tests and changelog updates. The review feedback focuses on the Angular implementation, highlighting that using a global mutable counter (nextGroupId) for generating unique IDs can cause hydration mismatches in Server-Side Rendering (SSR) environments. It is recommended to derive a stable, SSR-safe group name using a computed signal based on surfaceId, componentId, and dataContextPath. Additionally, it is suggested to only apply the name attribute to radio buttons, omitting it for checkboxes.

retz8 and others added 2 commits August 29, 2026 15:44
…nt.ts

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Jioh In <[email protected]>
… and data path

Addresses review on a2ui-project#2449: replace the module-level counter with a
computed name combining surfaceId, componentId, and the sanitized
dataContextPath. The derivation is deterministic (SSR-friendly) and the
path component disambiguates instances stamped from a list template
within one surface. Checkboxes no longer receive a name: the binding
uses attr.name so the null branch removes the attribute entirely,
matching the React renderer, rather than setting the string 'null' as
a name property binding would.

Also repairs the template applied from the review suggestion, which
called groupName() while groupName was still a plain property.
@github-actions github-actions Bot added the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Aug 30, 2026
@jacobsimionato
jacobsimionato requested review from ditman and josemontespg and removed request for ditman September 1, 2026 05:38
@jacobsimionato

Copy link
Copy Markdown
Collaborator

Assigning to @josemontesp who is working on catalogs recently.

I think this change looks quite good though!!

@github-actions github-actions Bot removed the status: needs-triage auto-managed: https://github.com/a2ui-project/a2ui/blob/main/scripts/triage.mjs label Sep 1, 2026

@josemontespg josemontespg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, thank you for the fix!

@josemontespg
josemontespg enabled auto-merge (squash) September 1, 2026 19:11
@josemontespg
josemontespg merged commit 12a724c into a2ui-project:main Sep 1, 2026
30 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in A2UI Sep 1, 2026
josemontespg added a commit that referenced this pull request Oct 1, 2026
### Summary

Every `ComponentNode` now carries an `id` that is unique across the whole document and stable for the node's lifetime. Renderers can use it directly as a React key, a DOM element `id`, or an accessibility target without keeping their own per-node bookkeeping.

### Changes

* `ComponentNode.id`: a string unique across the document (counter shared through `globalThis`, so duplicated bundles do not collide). The resolver assigns it when it creates a node, so it stays the same across property updates and changes only when the resolver replaces the node. `toJSON()` is unchanged and still reports the component id there.
* `nextNodeId()` in `src/resolution/node-id.ts` produces the ids (`a2ui-n<counter>`).

### Related issues

* #2447: `ChoicePicker` radio groups from different surfaces merged because the group name came from the component id, which is unique only within a surface, while HTML `name` and `id` are document-scoped. #2449 fixed it per renderer with per-instance ids; `node.id` gives every renderer one document-unique id per node to build such names from.
* #1410: basic catalog components do not render accessibility attributes. `aria-labelledby` and `aria-describedby` reference elements by document-unique `id`; `node.id` is a stable base for those references across React, Lit and Angular.

### Verification

* `typescript/web_core`: `yarn test` (868 passing). New tests cover uniqueness across resolvers, stability across a property update and a new id after remove and re-add.
* `renderers/react`, `renderers/lit`: existing unit tests pass on top of this change.
@retz8
retz8 deleted the fix/choicepicker-radio-group-collision branch October 6, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: With multiple surfaces, ChoicePickers with same component id merge into one radio group (React/Angular)

3 participants