Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(a11y): dangling aria-describedby in CheckboxInput & Switch + move Switch thumb to StyleX (#723)

Joey4d2ed4549a18
diff --git a/packages/core/src/CheckboxInput/XDSCheckboxInput.tsx b/packages/core/src/CheckboxInput/XDSCheckboxInput.tsx
index 5b5b2626de..592a562294 100644
--- a/packages/core/src/CheckboxInput/XDSCheckboxInput.tsx
+++ b/packages/core/src/CheckboxInput/XDSCheckboxInput.tsx
@@ -330,8 +330,9 @@ export function XDSCheckboxInput({
const isCheckedOrIndeterminate = isChecked || isIndeterminate;
// Build aria-describedby from description and status message
+ // Only include descriptionID when the element actually renders
const describedByParts: string[] = [];
- if (description) describedByParts.push(descriptionID);
+ if (description && !isLabelHidden) describedByParts.push(descriptionID);
if (status?.message) describedByParts.push(statusMessageID);
const ariaDescribedBy =
describedByParts.length > 0 ? describedByParts.join(' ') : undefined;
diff --git a/packages/core/src/Switch/XDSSwitch.tsx b/packages/core/src/Switch/XDSSwitch.tsx
index 85d3e7910c..6517c89241 100644
--- a/packages/core/src/Switch/XDSSwitch.tsx
+++ b/packages/core/src/Switch/XDSSwitch.tsx
@@ -131,6 +131,9 @@ const styles = stylex.create({
backgroundColor: colorVars['--color-gray-background'],
},
thumb: {
+ display: 'flex',
+ alignItems: 'center',
+ justifyContent: 'center',
borderRadius: radiusVars['--radius-rounded'],
backgroundColor: colorVars['--color-surface'],
transitionProperty: 'transform, width, height',
@@ -304,8 +307,9 @@ export function XDSSwitch({
const isOn = optimisticValue === true;
// Build aria-describedby from description and status message
+ // Only include descriptionID when the element actually renders
const describedByParts: string[] = [];
- if (description) describedByParts.push(descriptionID);
+ if (description && !isLabelHidden) describedByParts.push(descriptionID);
if (status?.message) describedByParts.push(statusMessageID);
const ariaDescribedBy =
describedByParts.length > 0 ? describedByParts.join(' ') : undefined;
@@ -353,12 +357,7 @@ export function XDSSwitch({
{...stylex.props(
styles.thumb,
isOn ? styles.thumbOn : styles.thumbOff,
- )}
- style={{
- display: 'flex',
- alignItems: 'center',
- justifyContent: 'center',
- }}>
+ )}>
{isBusy && <XDSSpinner size="sm" />}
</div>
</div>