Skip to content

fix(radio): remove deprecated invalid property in favor of group validation#5958

Open
JinMokai wants to merge 12 commits intoadobe:mainfrom
JinMokai:JinMokai/3571-remove-radio-invalid
Open

fix(radio): remove deprecated invalid property in favor of group validation#5958
JinMokai wants to merge 12 commits intoadobe:mainfrom
JinMokai:JinMokai/3571-remove-radio-invalid

Conversation

@JinMokai
Copy link

@JinMokai JinMokai commented Jan 11, 2026

fix(radio): remove deprecated invalid property in favor of group validation

Description

Removed the deprecated invalid property from the sp-radio component. Validation state should be managed at the sp-radio-group level.

  • Removed invalid property and aria-invalid handling from sp-radio.
  • Updated sp-radio-group to reflect the invalid state using the aria-invalid attribute.
  • Updated stories to remove the deprecated invalid controls on individual radio buttons.
  • Added unit tests to verify aria-invalid toggling on sp-radio-group.

Motivation and context

The invalid property on individual sp-radio elements was deprecated. Standard accessibility and design patterns for radio buttons dictate that validation should occur at the group level rather than on individual options. This change enforces that pattern and ensures the aria-invalid state is correctly applied to the group container.

This is my first contribution to the SWC components. My motivation is to learn more about accessibility knowledge, nothing else, just passion!

Related issue(s)

Screenshots (if appropriate)


Author's checklist

  • I have read the CONTRIBUTING and PULL_REQUESTS documents.
  • I have reviewed at the Accessibility Practices for this feature, see: Aria Practices
  • I have added automated tests to cover my changes.
  • I have included a well-written changeset if my change needs to be published.
  • I have included updated documentation if my change required it.

Reviewer's checklist

  • Includes a Github Issue with appropriate flag or Jira ticket number without a link
  • Includes thoughtfully written changeset if changes suggested include patch, minor, or major features
  • Automated tests cover all use cases and follow best practices for writing
  • Validated on all supported browsers
  • All VRTs are approved before the author can update Golden Hash

Manual review test cases

  • Descriptive Test Statement

    1. Go here
    2. Do this action
    3. Expect this result
  • Descriptive Test Statement

    1. Go here
    2. Do this action
    3. Expect this result

Device review

  • Did it pass in Desktop?
  • Did it pass in (emulated) Mobile?
  • Did it pass in (emulated) iPad?

@changeset-bot
Copy link

changeset-bot bot commented Jan 11, 2026

🦋 Changeset detected

Latest commit: 1223741

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 84 packages
Name Type
@spectrum-web-components/radio Patch
@spectrum-web-components/bundle Patch
documentation Patch
@spectrum-web-components/accordion Patch
@spectrum-web-components/action-bar Patch
@spectrum-web-components/action-button Patch
@spectrum-web-components/action-group Patch
@spectrum-web-components/action-menu Patch
@spectrum-web-components/alert-banner Patch
@spectrum-web-components/alert-dialog Patch
@spectrum-web-components/asset Patch
@spectrum-web-components/avatar Patch
@spectrum-web-components/badge Patch
@spectrum-web-components/breadcrumbs Patch
@spectrum-web-components/button-group Patch
@spectrum-web-components/button Patch
@spectrum-web-components/card Patch
@spectrum-web-components/checkbox Patch
@spectrum-web-components/clear-button Patch
@spectrum-web-components/close-button Patch
@spectrum-web-components/coachmark Patch
@spectrum-web-components/color-area Patch
@spectrum-web-components/color-field Patch
@spectrum-web-components/color-handle Patch
@spectrum-web-components/color-loupe Patch
@spectrum-web-components/color-slider Patch
@spectrum-web-components/color-wheel Patch
@spectrum-web-components/combobox Patch
@spectrum-web-components/contextual-help Patch
@spectrum-web-components/dialog Patch
@spectrum-web-components/divider Patch
@spectrum-web-components/dropzone Patch
@spectrum-web-components/field-group Patch
@spectrum-web-components/field-label Patch
@spectrum-web-components/help-text Patch
@spectrum-web-components/icon Patch
@spectrum-web-components/icons-ui Patch
@spectrum-web-components/icons-workflow Patch
@spectrum-web-components/icons Patch
@spectrum-web-components/iconset Patch
@spectrum-web-components/illustrated-message Patch
@spectrum-web-components/infield-button Patch
@spectrum-web-components/link Patch
@spectrum-web-components/menu Patch
@spectrum-web-components/meter Patch
@spectrum-web-components/modal Patch
@spectrum-web-components/number-field Patch
@spectrum-web-components/overlay Patch
@spectrum-web-components/picker-button Patch
@spectrum-web-components/picker Patch
@spectrum-web-components/popover Patch
@spectrum-web-components/progress-bar Patch
@spectrum-web-components/progress-circle Patch
@spectrum-web-components/search Patch
@spectrum-web-components/sidenav Patch
@spectrum-web-components/slider Patch
@spectrum-web-components/split-view Patch
@spectrum-web-components/status-light Patch
@spectrum-web-components/swatch Patch
@spectrum-web-components/switch Patch
@spectrum-web-components/table Patch
@spectrum-web-components/tabs Patch
@spectrum-web-components/tags Patch
@spectrum-web-components/textfield Patch
@spectrum-web-components/thumbnail Patch
@spectrum-web-components/toast Patch
@spectrum-web-components/tooltip Patch
@spectrum-web-components/top-nav Patch
@spectrum-web-components/tray Patch
@spectrum-web-components/underlay Patch
@spectrum-web-components/custom-vars-viewer Patch
@spectrum-web-components/story-decorator Patch
@spectrum-web-components/vrt-compare Patch
@spectrum-web-components/base Patch
@spectrum-web-components/grid Patch
@spectrum-web-components/opacity-checkerboard Patch
@spectrum-web-components/reactive-controllers Patch
@spectrum-web-components/shared Patch
@spectrum-web-components/styles Patch
@spectrum-web-components/theme Patch
@spectrum-web-components/truncated Patch
@spectrum-web-components/eslint-plugin Patch
example-project-rollup Patch
example-project-webpack Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@JinMokai
Copy link
Author

Hello reviewers, greetings to you. I have preliminarily completed what I believe needs to be done. If there are any errors or irregularities in this PR, please point them out, and I will address the issues and respond as soon as possible. Thank you once again!😊😊

@JinMokai JinMokai marked this pull request as ready for review January 14, 2026 02:00
@JinMokai JinMokai requested a review from a team as a code owner January 14, 2026 02:00
Copy link
Contributor

@blunteshwar blunteshwar left a comment

Choose a reason for hiding this comment

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

After removing
@property({ type: Boolean, reflect: true }) public invalid = false;
I don't see the property being added/declared in radio-group

Copy link
Contributor

@rubencarvalho rubencarvalho left a comment

Choose a reason for hiding this comment

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

Hey Jin! Thanks for the contribution. It is looking great!
Unfortunately, due to our semver policy, we can't remove the invalid property from sp-radio without a major version bump, which we can't do right now.

I do see a path forward here, though:
What if we have sp-radio-group observe invalid attribute changes on its child sp-radio elements and sync its own accessible invalid state accordingly, plus show a dev deprecation warning guiding users to the correct usage. This maintains backward compatibility while fixing the A11Y bug by centralizing the invalid state on the parent.

That said, if you have another approach, we're open to it! 😄
Thanks again for your contribution!

The sp-radio-group now manages the invalid state based on its child elements.
The standalone invalid property of sp-radio has been deprecated.
@JinMokai
Copy link
Author

hi, @rubencarvalho @blunteshwar
Thank you very much for the review! I've re-fixed a version. Your approach is reasonable, and I should consider backward compatibility, but I haven't figured out how to listen in a reasonable way yet. Currently, I achieve listening for the invalid attribute by getting all sp-radio elements under sp-radio-group and using a MutationObserver. I believe this is an attribute that's about to be deprecated, so it's unnecessary to add redundant code to different components. My current solution has passed all the test cases I wrote. If there are any issues or better suggestions, I will actively discuss and fix them. Thank you again 🙏😄

Copy link
Contributor

@Rajdeepc Rajdeepc left a comment

Choose a reason for hiding this comment

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

Getting there. I did spot a small bug and have a couple of performance oriented suggestions. Let me know when you’re ready for another round of review and I’ll take a closer look.

});

it('warns when [invalid] is used on children and updates group invalid state', async () => {
const consoleWarnSpy = spy(console, 'warn');
Copy link
Contributor

Choose a reason for hiding this comment

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

RadioGroup uses window.__swc.warn(...) but you are using spy(console.warn). If window.__swc.warn doesn't call console.warn in the test environment, tests will fail or become flaky.

@Rajdeepc Rajdeepc added the Status:Ready for review PR ready for review or re-review. label Jan 19, 2026
JinMokai and others added 2 commits January 22, 2026 07:09
- Keep `invalid` property on sp-radio for backward compatibility (marked @deprecated)
- RadioGroup now observes and syncs invalid state from child radios
- Add deprecation warning to guide users toward group-level validation
- Prevent clearing user-set invalid states with _managedInvalid flag
@JinMokai
Copy link
Author

hi @Rajdeepc
Regarding the issues you raised, I have fixed a version and added a test case. If there are any problems or potential issues with this PR, I will actively address and fix them. Thank you again 🙏

It is worth noting that the addition of the this._managedInvalid = false;
variable is to fix the test case for updating [aria-invalid] when [invalid] changes.

@caseyisonit caseyisonit added the Status:Addressing feedback PR owner is addressing review comments and will change label back to "Ready for review" when ready. label Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status:Addressing feedback PR owner is addressing review comments and will change label back to "Ready for review" when ready. Status:Ready for review PR ready for review or re-review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove deprecated support for aria-invalid state on the Radio Component

5 participants