Radio
Native Solid 2 fork. Original documentation and designs © WorkOS; historical posts retain their original context.
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">{target => target(Text, {
"as": "label",
"size": "2",
children: <>
<Radio name="example" value="1" defaultChecked />
Default
</>
})}</Flex>
<Flex asChild gap="2">{target => target(Text, {
"as": "label",
"size": "2",
children: <>
<Radio name="example" value="2" />
Comfortable
</>
})}</Flex>
<Flex asChild gap="2">{target => target(Text, {
"as": "label",
"size": "2",
children: <>
<Radio name="example" value="3" />
Compact
</>
})}</Flex>
</Flex>API Reference
This component is based on the input element and supports common margin props.
| Prop | Type | Default |
|---|---|---|
size | Responsive<"1" | "2" | "3"> | "2" |
variantThe visual variant to apply, see theme overview for more details. | "classic" | "surface" | "soft" | "surface" |
colorOverrides the accent color inherited from the Theme. See the color guide for more details. | enum | — |
highContrastUses a higher contrast color for the component. | boolean | — |
Examples
Size
Use the size prop to control the radio button size.
<Flex align="center" gap="4">
<Flex gap="2">
<Radio size="1" name="size-1" value="1" defaultChecked />
<Radio size="1" name="size-1" value="2" />
</Flex>
<Flex gap="2">
<Radio size="2" name="size-2" value="1" defaultChecked />
<Radio size="2" name="size-2" value="2" />
</Flex>
<Flex gap="2">
<Radio size="3" name="size-3" value="1" defaultChecked />
<Radio size="3" name="size-3" value="2" />
</Flex>
</Flex>Variant
Use the variant prop to control the visual style of the radio buttons.
<Flex align="center" gap="4">
<Flex gap="2">
<Radio variant="surface" name="surface" value="1" defaultChecked />
<Radio variant="surface" name="surface" value="2" />
</Flex>
<Flex gap="2">
<Radio variant="classic" name="classic" value="1" defaultChecked />
<Radio variant="classic" name="classic" value="2" />
</Flex>
<Flex gap="2">
<Radio variant="soft" name="soft" value="1" defaultChecked />
<Radio variant="soft" name="soft" value="2" />
</Flex>
</Flex>Color
Use the color prop to assign a specific color.
<Flex as="span" gap="2">
<Radio color="indigo" value="indigo" defaultChecked />
<Radio color="cyan" value="cyan" defaultChecked />
<Radio color="orange" value="orange" defaultChecked />
<Radio color="crimson" value="crimson" defaultChecked />
</Flex>High-contrast
Use the highContrast prop to increase color contrast with the background.
<Grid columns="5" display="inline-grid" gap="2">
<Radio color="indigo" value="indigo" defaultChecked />
<Radio color="cyan" value="cyan" defaultChecked />
<Radio color="orange" value="orange" defaultChecked />
<Radio color="crimson" value="crimson" defaultChecked />
<Radio color="gray" value="gray" defaultChecked />
<Radio color="indigo" value="indigo" defaultChecked highContrast />
<Radio color="cyan" value="cyan" defaultChecked highContrast />
<Radio color="orange" value="orange" defaultChecked highContrast />
<Radio color="crimson" value="crimson" defaultChecked highContrast />
<Radio color="gray" value="gray" defaultChecked highContrast />
</Grid>Alignment
Composing Radio within Text automatically centers it with the first line of text. It is automatically well-aligned with multi-line text too.
<Flex direction="column" gap="3">
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">{target => target(Text, {
"as": "label",
"size": "2",
children: <>
<Radio size="1" name="alignment-1" value="1" defaultChecked />
Default
</>
})}</Flex>
<Flex asChild gap="2">{target => target(Text, {
"as": "label",
"size": "2",
children: <>
<Radio size="1" name="alignment-1" value="2" />
Compact
</>
})}</Flex>
</Flex>
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">{target => target(Text, {
"as": "label",
"size": "3",
children: <>
<Radio size="2" name="alignment-2" value="1" defaultChecked />
Default
</>
})}</Flex>
<Flex asChild gap="2">{target => target(Text, {
"as": "label",
"size": "3",
children: <>
<Radio size="2" name="alignment-2" value="2" />
Compact
</>
})}</Flex>
</Flex>
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">{target => target(Text, {
"as": "label",
"size": "4",
children: <>
<Radio size="3" name="alignment-3" value="1" defaultChecked />
Default
</>
})}</Flex>
<Flex asChild gap="2">{target => target(Text, {
"as": "label",
"size": "4",
children: <>
<Radio size="3" name="alignment-3" value="2" />
Compact
</>
})}</Flex>
</Flex>
</Flex>Disabled
Use the native disabled attribute to create a disabled radio button.
<Flex direction="column" gap="3">
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">{target => target(Text, {
"as": "label",
"size": "2",
children: <>
<Radio name="enabled" value="1" defaultChecked />
On
</>
})}</Flex>
<Flex asChild gap="2">{target => target(Text, {
"as": "label",
"size": "2",
children: <>
<Radio name="enabled" value="2" />
Off
</>
})}</Flex>
</Flex>
<Flex align="start" direction="column" gap="1">
<Flex asChild gap="2">{target => target(Text, {
"as": "label",
"size": "2",
"color": "gray",
children: <>
<Radio disabled name="disabled" value="1" defaultChecked />
On
</>
})}</Flex>
<Flex asChild gap="2">{target => target(Text, {
"as": "label",
"size": "2",
"color": "gray",
children: <>
<Radio disabled name="disabled" value="2" />
Off
</>
})}</Flex>
</Flex>
</Flex>