Skip to content
Cynosurev0.5.0
SearchStorybookGitHubnpmColour mode: System. Switch to Light

Components / More

Choice

The row a choice control sits in: the control, its label and an optional description, the whole row clickable. Checkbox, Switch and each RadioGroup option are Choice rows that draw their own control.

Label names and toggles the control

When to useLink to "When to use"

  • Building a new kind of choice control (a star, a coloured chip) that needs the same label, description, forms and touch behaviour as a checkbox.

Use something else when:

UsageLink to "Usage"

tsx
Copy
import { Choice, ChoiceBase } from "@arshad-shah/cynosure";

<Choice
  label="Show hidden files"
  description="Dotfiles and system folders."
  onChange={setShown}
  control={(input) => (
    <span className="my-star">
      <ChoiceBase {...input} type="checkbox" />
    </span>
  )}
/>

control receives the input's props: its id, aria-labelledby, aria-describedby, checked or defaultChecked, onChange, and name, value, required and disabled. Spread them onto ChoiceBase, which hides the native input over your drawing. The input must be a direct child of the element control returns. onChange on Choice receives the new checked boolean.

Controlled and uncontrolled

Done styleLink to "Done style"

strikeWhenChecked strikes through and mutes the label while the input is checked (and not indeterminate), and mutes the description with it. An input placed inside the label does not count.

Strike when checked and its tokens

PropsLink to "Props"

Every prop of Choice
PropWhat it doesTypeDefault
controlRequired
Draws the control, given the props for its native input. The input must be a direct child of the element this returns (the label's strike follows it).(input: ChoiceInput) => ReactNode
labelRequired
The control's label. Pressing it toggles the control.ReactNode
strikeWhenChecked
While the control is checked (and not mixed), the label is struck through and muted, and the description muted, so a done task reads as done. Default false.booleanfalse
className
Added to the root element (the label that wraps the row), for layout.string
style
Layout only, applied to the root element.CSSProperties
disabled
It cannot be changed and is not submitted with a form.boolean
name
Name it is submitted under in a form, when on.string
value
The value submitted with name when on. The browser sends "on" when this is not set.string
defaultChecked
On at first, when uncontrolled.boolean
id
Id of the native input; one is generated when not set.string
onChange
Called when the person turns it on or off, with the new state.((checked: boolean) => void)
description
Help text shown under the label and read with the control.ReactNode
checked
Controlled: whether it is on.boolean
required
It must be on for the form to submit.boolean
size
Size of the control and its text. Default "md".Size"md"

Generated from the type definitions in @arshad-shah/cynosure 0.5.0.

Behaviour and accessibilityLink to "Behaviour and accessibility"

Behaviour and accessibility, table 1
InputResult
Click or tap the control, label or descriptionToggles the input
Space on the focused inputToggles it
  • Name and description: the label names the input and the description is linked with aria-describedby.
  • Forms: the input is native, so FormData, reset and required work as the browser does them.
  • Disabled: the input is disabled and the row is dimmed with a not-allowed cursor.
  • Done style: the checked state is what is announced; the strike only shows it. In forced colours the strike stays, in the system text colour; the colour change stops under reduced motion.

TouchLink to "Touch"

The row is at least 24px tall, and 44px on coarse pointers, where the control is centred on the text.

ThemingLink to "Theming"

Theming, table 2
TokenControls
--cy-choice-gapSpace between the control and the text. Default --cy-space-4.
--cy-choice-done-colorLabel and description colour of a checked strikeWhenChecked row. Default --cy-color-muted. Checkbox sets it from --cy-checkbox-done-color.
--cy-choice-strike-widthThickness of the strike. Default: the border width, or 1/16 of the text size when that is larger. Checkbox sets it from --cy-checkbox-strike-width.
ts
Copy
createTheme({ components: { choice: { gap: "12px" } } });

Checkbox · Switch · RadioGroup · ChoiceBase

These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.

Getting started
Theming
Icons
Accessibility
Code editors and highlighters
Using Cynosure without React
Build-tool adapters
Components
Accordion
AppShell
AspectRatio
Breadcrumbs
Calendar
Card
Container
Disclosure
Divider
DocumentViewport
Grid
Inline
PageHeader
PanZoomCanvas
ScrollArea
SideNav
SortableList
SplitPane
Stack
StatusBar
Tabs
TitleBar
Toolbar
Tree
VirtualList
ZoomControls
Announcer
Avatar
Badge
CodeBlock
DescriptionList
EmptyState
ErrorBoundary
Field
Heading
IconTile
Image
Kbd
List
LoadingDots
Notice
ProgressBar
Prose
Skeleton
Stat
Steps
Table
Text
Button
Checkbox
Checklist
ColorField
ColorSwatches
Combobox
CompareSlider
CopyButton
DateField
FileDrop
IconButton
KeyValueEditor
Link
NumberField
Pagination
PathField
RadioGroup
SearchField
SegmentedControl
Select
SelectionFrame
SignaturePad
Slider
Switch
TagInput
TextArea
TextField
ThemeToggle
TimeField
ButtonBase
ChoiceBase
DialogBase
FileInputBase
HiddenValue
Icon
InputBase
LinkBase
LiveRegion
TextAreaBase
ChatMessage
Choice
DataGrid
DeviceFrame
HighlightedText
HotkeyField
ListRow
OptionList
OverlayFrame
QRCode
RowActions
Section
SiteFooter
SiteHeader
SkipLink
SortButton
VisuallyHidden
CommandPalette
ContextMenu
Dialog
FloatingToolbar
HoverCard
Menu
Menubar
Popover
ProgressOverlay
Sheet
Toast
Tooltip
Changelog