Skip to content

Switch: adopt new React Aria API - #846

Open
mkernohanbc wants to merge 3 commits into
feature/refactor-radiofrom
feature/refactor-switch
Open

Switch: adopt new React Aria API#846
mkernohanbc wants to merge 3 commits into
feature/refactor-radiofrom
feature/refactor-switch

Conversation

@mkernohanbc

Copy link
Copy Markdown
Contributor

This PR closes #722. It refactors the Switch component to adopt the new API shipped in react-aria-components v1.18.0. Switch now uses the SwitchField and SwitchButton subcomponents internally. Switch now supports additional description and error message fields, displayed below the switch and label. This change is non-breaking. This PR also includes a refactor of Switch's CSS to conform to stylelint's no-descending-specificity rule (see #841.)


Stack created with GitHub Stacks CLIGive Feedback 💬

@mkernohanbc
mkernohanbc requested a review from a team as a code owner August 20, 2026 18:13
@mkernohanbc mkernohanbc self-assigned this Aug 20, 2026
@mkernohanbc mkernohanbc linked an issue Aug 20, 2026 that may be closed by this pull request
@mkernohanbc mkernohanbc added the react-components Changes or issues affecting the design-system-react-components package label Aug 20, 2026
@mkernohanbc
mkernohanbc requested a review from ty2k August 20, 2026 18:17
@ty2k
ty2k requested a balanced review from Copilot August 21, 2026 22:24

Copilot AI 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.

Pull request overview

Refactors Switch to React Aria’s new field/button API and adds validation messaging and descriptions.

Changes:

  • Adopted SwitchField and SwitchButton.
  • Added description and error-message support.
  • Refactored Switch styling and Storybook documentation.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Switch.tsx Implements the new API and validation fields.
Switch.css Updates structure and state styling.
Switch.stories.tsx Adds controls and description example.
Switch.mdx Documents helper text.
Checkbox.stories.tsx Adds an error-message control.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

<ReactAriaSwitchButton className="bcds-react-aria-Switch--Button">
{({ isSelected, isDisabled }) => (
<>
{labelPosition === "left" && <>{children}</>}
Comment on lines +57 to +62
<FieldError className="bcds-react-aria-Switch--Error">
<>
<SvgExclamationIcon />
{errorMessage}
</>
</FieldError>
Comment on lines +106 to +110
> .bcds-react-aria-Switch--Handle {
background-color: var(--theme-gray-10);
border: var(--layout-border-width-medium) solid
var(--surface-color-border-default);
}
Comment on lines +114 to +116
.bcds-react-aria-Switch--Button[data-selected]
> .bcds-react-aria-Switch--Track {
background-color: var(--surface-color-primary-default);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

react-components Changes or issues affecting the design-system-react-components package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor Switch

2 participants