Skip to content

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

TypeScript

fix(core): align checkbox, radio, and switch control sizes (#4497)

Cindy Zhang08bb53c8d662
diff --git a/.changeset/control-size-alignment.md b/.changeset/control-size-alignment.md
new file mode 100644
index 0000000000..0dda8d080d
--- /dev/null
+++ b/.changeset/control-size-alignment.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] CheckboxInput, RadioList, Switch: align control sizes. The visible checkbox and radio controls now fill their size exactly (20px at `sm`, 24px at `md`) instead of being inset 2px. The `sm` Switch track is now 32px wide with a 2px inset.
+
+@cixzhang
diff --git a/apps/storybook/stories/ControlSizeComparison.stories.tsx b/apps/storybook/stories/ControlSizeComparison.stories.tsx
new file mode 100644
index 0000000000..ccd18aa312
--- /dev/null
+++ b/apps/storybook/stories/ControlSizeComparison.stories.tsx
@@ -0,0 +1,88 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+import {useState} from 'react';
+import type {Meta, StoryObj} from '@storybook/react';
+import {CheckboxInput} from '@astryxdesign/core/CheckboxInput';
+import {RadioList, RadioListItem} from '@astryxdesign/core/RadioList';
+import {Switch} from '@astryxdesign/core/Switch';
+import {Stack, Text} from '@astryxdesign/core';
+
+/**
+ * Side-by-side comparison of the selection controls — `CheckboxInput`,
+ * `RadioList`, and `Switch` — at matching sizes, so their proportions can be
+ * observed together.
+ *
+ * Use this view to spot-check size consistency: the control glyphs and their
+ * hit-target wrappers should feel visually aligned across all three at a given
+ * size.
+ */
+const meta: Meta = {
+ title: 'Core/Control Size Comparison',
+ parameters: {
+ layout: 'padded',
+ },
+};
+
+export default meta;
+type Story = StoryObj;
+
+type Size = 'sm' | 'md';
+
+function ControlRow({size}: {size: Size}) {
+ const [checked, setChecked] = useState(true);
+ const [radio, setRadio] = useState('a');
+ const [on, setOn] = useState(true);
+
+ return (
+ <Stack direction="horizontal" gap={8} align="center">
+ <CheckboxInput
+ label="Checkbox"
+ size={size}
+ value={checked}
+ onChange={setChecked}
+ />
+ <RadioList
+ label="Radio"
+ isLabelHidden
+ size={size}
+ value={radio}
+ onChange={setRadio}>
+ <RadioListItem label="Radio" value="a" />
+ </RadioList>
+ <Switch label="Switch" size={size} value={on} onChange={setOn} />
+ </Stack>
+ );
+}
+
+/**
+ * All three controls rendered at each size, grouped by size so the controls can
+ * be compared directly against each other.
+ */
+export const AllSizes: Story = {
+ render: () => (
+ <Stack direction="vertical" gap={8}>
+ {(['sm', 'md'] as const).map(size => (
+ <Stack key={size} direction="vertical" gap={3}>
+ <Text type="label" weight="bold">
+ size="{size}"
+ </Text>
+ <ControlRow size={size} />
+ </Stack>
+ ))}
+ </Stack>
+ ),
+};
+
+/**
+ * Small (`sm`) controls only.
+ */
+export const Small: Story = {
+ render: () => <ControlRow size="sm" />,
+};
+
+/**
+ * Medium (`md`, default) controls only.
+ */
+export const Medium: Story = {
+ render: () => <ControlRow size="md" />,
+};
diff --git a/packages/core/src/CheckboxInput/CheckboxInput.tsx b/packages/core/src/CheckboxInput/CheckboxInput.tsx
index b01c88e04d..b916270d50 100644
--- a/packages/core/src/CheckboxInput/CheckboxInput.tsx
+++ b/packages/core/src/CheckboxInput/CheckboxInput.tsx
@@ -198,12 +198,12 @@ const wrapperSizeStyles = stylex.create({
const checkboxSizeStyles = stylex.create({
sm: {
- width: 18,
- height: 18,
+ width: 20,
+ height: 20,
},
md: {
- width: 22,
- height: 22,
+ width: 24,
+ height: 24,
},
});
diff --git a/packages/core/src/RadioList/RadioList.tsx b/packages/core/src/RadioList/RadioList.tsx
index e169397785..d4802db6eb 100644
--- a/packages/core/src/RadioList/RadioList.tsx
+++ b/packages/core/src/RadioList/RadioList.tsx
@@ -146,8 +146,8 @@ export interface RadioListProps extends Omit<
status?: InputStatus;
/**
* The size of the radio controls.
- * - 'sm': Compact size (18px radio, 20px wrapper)
- * - 'md': Default size (22px radio, 24px wrapper)
+ * - 'sm': Compact size (20px radio)
+ * - 'md': Default size (24px radio)
* @default 'md'
*/
size?: RadioListSize;
diff --git a/packages/core/src/RadioList/RadioListItem.tsx b/packages/core/src/RadioList/RadioListItem.tsx
index 5a0c9ed45d..c0f75e1d50 100644
--- a/packages/core/src/RadioList/RadioListItem.tsx
+++ b/packages/core/src/RadioList/RadioListItem.tsx
@@ -140,12 +140,12 @@ const wrapperSizeStyles = stylex.create({
const radioSizeStyles = stylex.create({
sm: {
- width: 18,
- height: 18,
+ width: 20,
+ height: 20,
},
md: {
- width: 22,
- height: 22,
+ width: 24,
+ height: 24,
},
});
diff --git a/packages/core/src/Switch/Switch.doc.mjs b/packages/core/src/Switch/Switch.doc.mjs
index e077df0b07..ce5dd83c17 100644
--- a/packages/core/src/Switch/Switch.doc.mjs
+++ b/packages/core/src/Switch/Switch.doc.mjs
@@ -6,7 +6,14 @@ export const docs = {
name: 'Switch',
displayName: 'Switch',
category: 'Data Input',
- keywords: ["switch","toggle","onoff","flipswitch","boolean","toggleswitch"],
+ keywords: [
+ 'switch',
+ 'toggle',
+ 'onoff',
+ 'flipswitch',
+ 'boolean',
+ 'toggleswitch',
+ ],
props: [
{
name: 'ref',
@@ -65,7 +72,8 @@ export const docs = {
{
name: 'size',
type: "'sm' | 'md'",
- description: 'Size variant controlling track and thumb dimensions. sm (34x20px) matches sm checkbox/radio vertical rhythm; md (40x24px, default) matches md checkbox/radio vertical rhythm.',
+ description:
+ 'Size variant controlling track and thumb dimensions. sm (32x20px) matches sm checkbox/radio vertical rhythm; md (40x24px, default) matches md checkbox/radio vertical rhythm.',
default: "'md'",
},
{
@@ -113,7 +121,8 @@ export const docs = {
{
name: 'labelIcon',
type: 'IconType',
- description: 'Icon displayed before the label text. See `astryx docs icons` for valid semantic names.',
+ description:
+ 'Icon displayed before the label text. See `astryx docs icons` for valid semantic names.',
},
{
name: 'labelTooltip',
@@ -138,20 +147,51 @@ export const docs = {
],
theming: {
targets: [
- {className: 'astryx-switch', visualProps: ['size'], states: ['checked', 'disabled']},
- {className: 'astryx-switch-thumb', visualProps: ['size'], states: ['checked']},
- {className: 'astryx-switch-field', visualProps: ['labelPosition', 'labelSpacing']},
+ {
+ className: 'astryx-switch',
+ visualProps: ['size'],
+ states: ['checked', 'disabled'],
+ },
+ {
+ className: 'astryx-switch-thumb',
+ visualProps: ['size'],
+ states: ['checked'],
+ },
+ {
+ className: 'astryx-switch-field',
+ visualProps: ['labelPosition', 'labelSpacing'],
+ },
],
},
usage: {
description:
'A toggle control for on/off states that take effect immediately. Supports labels, descriptions, loading states, and validation. Use it for settings or preferences that apply instantly. For changes requiring a form submission, use a checkbox instead.',
bestPractices: [
- { guidance: true, description: 'Use for settings that apply immediately; the toggle should take effect without a separate save action.' },
- { guidance: true, description: 'Pair with a clear, concise label that describes the setting being controlled.' },
- { guidance: false, description: 'Use for options that require a form submission to take effect; use a checkbox instead.' },
- { guidance: false, description: 'Use a switch for multi-state values; it\'s strictly on/off.' },
- { guidance: false, description: 'Wrap a disabled switch in Tooltip to explain why it is disabled; disabled controls swallow the hover events the wrapper needs. Use the disabledMessage prop instead.' },
+ {
+ guidance: true,
+ description:
+ 'Use for settings that apply immediately; the toggle should take effect without a separate save action.',
+ },
+ {
+ guidance: true,
+ description:
+ 'Pair with a clear, concise label that describes the setting being controlled.',
+ },
+ {
+ guidance: false,
+ description:
+ 'Use for options that require a form submission to take effect; use a checkbox instead.',
+ },
+ {
+ guidance: false,
+ description:
+ "Use a switch for multi-state values; it's strictly on/off.",
+ },
+ {
+ guidance: false,
+ description:
+ 'Wrap a disabled switch in Tooltip to explain why it is disabled; disabled controls swallow the hover events the wrapper needs. Use the disabledMessage prop instead.',
+ },
],
},
};
@@ -169,8 +209,7 @@ export const docsZh = {
{
name: 'label',
type: 'string',
- description:
- '开关的标签文本(始终渲染以确保无障碍性)。',
+ description: '开关的标签文本(始终渲染以确保无障碍性)。',
required: true,
},
{
@@ -193,15 +232,13 @@ export const docsZh = {
{
name: 'isLoading',
type: 'boolean',
- description:
- '开关是否处于加载状态,在滑块内显示旋转器。',
+ description: '开关是否处于加载状态,在滑块内显示旋转器。',
default: 'false',
},
{
name: 'isLabelHidden',
type: 'boolean',
- description:
- '视觉上隐藏标签,同时保持屏幕阅读器的无障碍性。',
+ description: '视觉上隐藏标签,同时保持屏幕阅读器的无障碍性。',
default: 'false',
},
{
@@ -218,7 +255,8 @@ export const docsZh = {
{
name: 'htmlName',
type: 'string',
- description: '底层复选框输入的 HTML name 属性,用于表单提交(开启时提交 "on")。',
+ description:
+ '底层复选框输入的 HTML name 属性,用于表单提交(开启时提交 "on")。',
},
{
name: 'disabledMessage',
@@ -229,15 +267,13 @@ export const docsZh = {
{
name: 'isOptional',
type: 'boolean',
- description:
- '字段是否为可选。与 isRequired 互斥。',
+ description: '字段是否为可选。与 isRequired 互斥。',
default: 'false',
},
{
name: 'isRequired',
type: 'boolean',
- description:
- '开关是否为必填。与 isOptional 互斥。',
+ description: '开关是否为必填。与 isOptional 互斥。',
default: 'false',
},
{
@@ -264,14 +300,12 @@ export const docsZh = {
{
name: 'labelTooltip',
type: 'string',
- description:
- '在标签末尾的信息图标中显示的工具提示文本。',
+ description: '在标签末尾的信息图标中显示的工具提示文本。',
},
{
name: 'labelPosition',
type: "'start' | 'end'",
- description:
- '标签出现在开关的哪一侧。"start" 将标签放在开关前面。',
+ description: '标签出现在开关的哪一侧。"start" 将标签放在开关前面。',
default: "'end'",
},
{
@@ -284,20 +318,51 @@ export const docsZh = {
],
theming: {
targets: [
- {className: 'astryx-switch', visualProps: ['size'], states: ['checked', 'disabled']},
- {className: 'astryx-switch-thumb', visualProps: ['size'], states: ['checked']},
- {className: 'astryx-switch-field', visualProps: ['labelPosition', 'labelSpacing']},
+ {
+ className: 'astryx-switch',
+ visualProps: ['size'],
+ states: ['checked', 'disabled'],
+ },
+ {
+ className: 'astryx-switch-thumb',
+ visualProps: ['size'],
+ states: ['checked'],
+ },
+ {
+ className: 'astryx-switch-field',
+ visualProps: ['labelPosition', 'labelSpacing'],
+ },
],
},
usage: {
description:
'A toggle control for on/off states that take effect immediately. Supports labels, descriptions, loading states, and validation. Use it for settings or preferences that apply instantly. For changes requiring a form submission, use a checkbox instead.',
bestPractices: [
- { guidance: true, description: 'Use for settings that apply immediately; the toggle should take effect without a separate save action.' },
- { guidance: true, description: 'Pair with a clear, concise label that describes the setting being controlled.' },
- { guidance: false, description: 'Use for options that require a form submission to take effect; use a checkbox instead.' },
- { guidance: false, description: 'Use a switch for multi-state values; it\'s strictly on/off.' },
- { guidance: false, description: 'Wrap a disabled switch in Tooltip to explain why it is disabled; disabled controls swallow the hover events the wrapper needs. Use the disabledMessage prop instead.' },
+ {
+ guidance: true,
+ description:
+ 'Use for settings that apply immediately; the toggle should take effect without a separate save action.',
+ },
+ {
+ guidance: true,
+ description:
+ 'Pair with a clear, concise label that describes the setting being controlled.',
+ },
+ {
+ guidance: false,
+ description:
+ 'Use for options that require a form submission to take effect; use a checkbox instead.',
+ },
+ {
+ guidance: false,
+ description:
+ "Use a switch for multi-state values; it's strictly on/off.",
+ },
+ {
+ guidance: false,
+ description:
+ 'Wrap a disabled switch in Tooltip to explain why it is disabled; disabled controls swallow the hover events the wrapper needs. Use the disabledMessage prop instead.',
+ },
],
},
};
@@ -309,11 +374,31 @@ export const docsDense = {
description:
'A toggle control for on/off states that take effect immediately. Supports labels, descriptions, loading states, and validation. Use it for settings or preferences that apply instantly. For changes requiring a form submission, use a checkbox instead.',
bestPractices: [
- { guidance: true, description: 'Use for settings that apply immediately; the toggle should take effect without a separate save action.' },
- { guidance: true, description: 'Pair with a clear, concise label that describes the setting being controlled.' },
- { guidance: false, description: 'Use for options that require a form submission to take effect; use a checkbox instead.' },
- { guidance: false, description: 'Use a switch for multi-state values; it\'s strictly on/off.' },
- { guidance: false, description: 'Wrap a disabled switch in Tooltip to explain why it is disabled; disabled controls swallow the hover events the wrapper needs. Use the disabledMessage prop instead.' },
+ {
+ guidance: true,
+ description:
+ 'Use for settings that apply immediately; the toggle should take effect without a separate save action.',
+ },
+ {
+ guidance: true,
+ description:
+ 'Pair with a clear, concise label that describes the setting being controlled.',
+ },
+ {
+ guidance: false,
+ description:
+ 'Use for options that require a form submission to take effect; use a checkbox instead.',
+ },
+ {
+ guidance: false,
+ description:
+ "Use a switch for multi-state values; it's strictly on/off.",
+ },
+ {
+ guidance: false,
+ description:
+ 'Wrap a disabled switch in Tooltip to explain why it is disabled; disabled controls swallow the hover events the wrapper needs. Use the disabledMessage prop instead.',
+ },
],
},
propDescriptions: {
@@ -321,7 +406,8 @@ export const docsDense = {
label: 'Label text (always rendered for a11y).',
value: 'Whether switch is on or off.',
onChange: 'Fired when switch state changes.',
- changeAction: 'Async action after onChange; triggers optimistic UI + loading spinner until resolved.',
+ changeAction:
+ 'Async action after onChange; triggers optimistic UI + loading spinner until resolved.',
isLoading: 'Loading state; shows spinner in thumb.',
isLabelHidden: 'Visually hides label; still accessible to screen readers.',
description: 'Description text below label.',
@@ -329,12 +415,14 @@ export const docsDense = {
htmlName: 'HTML name attr for the checkbox; submits "on" when on.',
isOptional: 'Whether field is optional; mutually exclusive w/ isRequired.',
isRequired: 'Whether switch is required; mutually exclusive w/ isOptional.',
- status: 'Status indicator w/ type + message; colored message box, sets aria-invalid on error.',
+ status:
+ 'Status indicator w/ type + message; colored message box, sets aria-invalid on error.',
onFocus: 'Fired when switch receives focus.',
onBlur: 'Fired when switch loses focus.',
labelIcon: 'Icon before label text.',
labelTooltip: 'Tooltip text in info icon at label end.',
labelPosition: 'Which side label appears; "start" places before switch.',
- labelSpacing: 'Spacing behavior; "hug" places next to each other, "spread" pushes to opposite ends (full width). "default" is deprecated alias for "hug".',
+ labelSpacing:
+ 'Spacing behavior; "hug" places next to each other, "spread" pushes to opposite ends (full width). "default" is deprecated alias for "hug".',
},
-};
\ No newline at end of file
+};
diff --git a/packages/core/src/Switch/Switch.tsx b/packages/core/src/Switch/Switch.tsx
index 462d2a7b40..40f6f1f076 100644
--- a/packages/core/src/Switch/Switch.tsx
+++ b/packages/core/src/Switch/Switch.tsx
@@ -49,7 +49,7 @@ import {VisuallyHidden} from '../VisuallyHidden';
const wrapperSizeStyles = stylex.create({
sm: {
- width: 34,
+ width: 32,
height: 20,
},
md: {
@@ -60,7 +60,7 @@ const wrapperSizeStyles = stylex.create({
const inputSizeStyles = stylex.create({
sm: {
- width: 34,
+ width: 32,
height: 20,
},
md: {
@@ -71,9 +71,9 @@ const inputSizeStyles = stylex.create({
const trackSizeStyles = stylex.create({
sm: {
- width: 34,
+ width: 32,
height: 20,
- padding: 3,
+ padding: 2,
},
md: {
width: 40,
@@ -84,8 +84,8 @@ const trackSizeStyles = stylex.create({
const thumbOffSizeStyles = stylex.create({
sm: {
- width: 12,
- height: 12,
+ width: 14,
+ height: 14,
transform: 'translateX(0)',
},
md: {
@@ -99,7 +99,7 @@ const thumbOnSizeStyles = stylex.create({
sm: {
width: 16,
height: 16,
- transform: 'translateX(13px)',
+ transform: 'translateX(12px)',
},
md: {
width: 20,