Switch: adopt new React Aria API - #846
Open
mkernohanbc wants to merge 3 commits into
Open
Conversation
Open
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors Switch to React Aria’s new field/button API and adds validation messaging and descriptions.
Changes:
- Adopted
SwitchFieldandSwitchButton. - 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR closes #722. It refactors the Switch component to adopt the new API shipped in
react-aria-componentsv1.18.0. Switch now uses theSwitchFieldandSwitchButtonsubcomponents 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'sno-descending-specificityrule (see #841.)Stack created with GitHub Stacks CLI • Give Feedback 💬