CwRadio

Themed radio input with native form behavior. Group radios by sharing the same name and bind:group value.

Stacked Group

Irrigation mode

Selected: automatic

CwRadio group example Copy code
<script lang="ts">
	import { CwRadio } from '@cropwatchdevelopment/cwui';

	let irrigationMode = $state('automatic');
</script>

<fieldset>
	<legend>Irrigation mode</legend>
	<CwRadio
		name="irrigation-mode"
		value="automatic"
		label="Automatic"
		description="Follow the scheduled automation rules."
		bind:group={irrigationMode}
	/>
	<CwRadio
		name="irrigation-mode"
		value="manual"
		label="Manual"
		description="Only run when an operator starts a cycle."
		bind:group={irrigationMode}
	/>
</fieldset>

Compact Row

Channel: email

Disabled Option

Publish scope
Documentation Upgrade

Start here

CwRadio is the library radio input for single-choice selections. Group radios by sharing the same `name` and `bind:group`, then keep the labels specific enough that each option stands on its own.

How to think about it

  1. Bind one shared group value Each radio gets its own `value`, but the whole group points at one shared `bind:group` selection.
  2. Use a common `name` for real form grouping Matching `name` attributes keep the radios behaving like one native radio set during form submission and validation.
  3. Add descriptions only when the options need explanation Simple choices can use label-only radios. Turn on `description` when users need help understanding the impact of each option.

Props and callbacks

For a real radio group, every option should share the same `name` and `bind:group` target.

APITypeDetails
group
CwRadioValue | nullShared selected value for the radio group.
value

Default: on

CwRadioValueValue emitted when this radio becomes selected.
label
stringPrimary radio label.
description
stringOptional supporting text under the label.
id
stringOptional explicit input id.
oninput
(value: CwRadioValue, event: Event) => voidRuns when this radio receives the input event and becomes selected.
onchange
(value: CwRadioValue, event: Event) => voidRuns when this radio receives the change event and becomes selected.
...native radio attrs
HTMLInputAttributesPass `name`, `required`, `disabled`, `aria-*`, and standard radio attributes through to the real input.

Copy-paste examples

These snippets intentionally show the full public API surface the live demo relies on.

Single-choice settings group

This is the normal form pattern for mutually exclusive options.

Single-choice settings group Copy code
<script lang="ts">
	let irrigationMode = $state('automatic');
</script>

<CwRadio
	name="irrigation-mode"
	value="automatic"
	label="Automatic"
	description="Follow the scheduled automation rules."
	bind:group={irrigationMode}
/>
<CwRadio
	name="irrigation-mode"
	value="manual"
	label="Manual"
	description="Only run when an operator starts a cycle."
	bind:group={irrigationMode}
/>
Immediate side effects on selection

Use callbacks when changing the selected option should trigger follow-up work.

Immediate side effects on selection Copy code
<CwRadio
	name="notification-channel"
	value="sms"
	label="SMS"
	oninput={(value) => console.log('input', value)}
	onchange={(value) => savePreference('notificationChannel', value)}
/>