Forms & Inputs
Radio
A single radio control — a circle + label. Selection is mutually exclusive and owned by the parent nana-radio-group, which manages the checked value, keyboard roving and form association; on its own a radio still renders and fires nana-change. Rebrand by overriding --nana-radio-accent (or the global --nana-surface-accent) — no need to fork the component.
Preview
Section titled “Preview”<nana-radio-group value="card" label="Payment">
<nana-radio value="card">Card</nana-radio>
<nana-radio value="cash">Cash</nana-radio>
</nana-radio-group> <script lang="ts">
import { NanaRadio, NanaRadioGroup } from '$lib/components/ui/radio';
let plan = $state('pro');
</script>
<NanaRadioGroup label="Plan" bind:value={plan}>
<NanaRadio value="free">Free</NanaRadio>
<NanaRadio value="pro">Pro</NanaRadio>
<NanaRadio value="team" disabled>Team</NanaRadio>
</NanaRadioGroup> Installation
Section titled “Installation”Install the package for a versioned dependency:
npm install @nana-tec/ui-componentsOr copy the source in and own it:
npx @nana-tec/ui add radio --framework web-componentsnpx @nana-tec/ui add radio --framework svelteLands in src/lib/components/ui/radio/ as NanaRadio.svelte and NanaRadioGroup.svelte, styled with Tailwind
classes that resolve to the design tokens. Requires Tailwind v4.
Import the autoloader once, in your app's entry point. Every <nana-*> tag then works anywhere, and
each component downloads only the first time a page uses it:
import "@nana-tec/ui-components/autoloader";import "@nana-tec/ui-components/theme";The second line gives every component the Nana look and the design tokens behind it. Leave it out to style the components entirely yourself.
Import a component directly when it must be ready at once: on screen at first paint, or when you call its methods straight away. The two mix freely:
import "@nana-tec/ui-components/radio";
Copied in with npx @nana-tec/ui add radio? Import your project's own
@/lib/nana-ui/autoloader.js once instead; the CLI keeps it up to date.
<nana-radio-group value="card" label="Payment"> <nana-radio value="card">Card</nana-radio> <nana-radio value="cash">Cash</nana-radio></nana-radio-group><script lang="ts"> import { NanaRadio, NanaRadioGroup } from '$lib/components/ui/radio';
let plan = $state('pro');</script>
<NanaRadioGroup label="Plan" bind:value={plan}> <NanaRadio value="free">Free</NanaRadio> <NanaRadio value="pro">Pro</NanaRadio> <NanaRadio value="team" disabled>Team</NanaRadio></NanaRadioGroup>The group shares its name, size and disabled with every radio through
context, so the children need only a value.
orientation="horizontal" lays the options out in a row.
For options drawn as buttons, NanaRadioButton goes in the same group; see
Radio Button.
With descriptions
Section titled “With descriptions”Each nana-radio takes a label and optional description.
<nana-radio-group
label="Notifications"
name="notify"
value="email"
helper-text="Choose how we reach you."
>
<nana-radio
value="email"
label="Email"
description="Updates to your inbox"
></nana-radio>
<nana-radio
value="sms"
label="SMS"
description="Texts to your phone"
></nana-radio>
<nana-radio
value="push"
label="Push"
description="In-app notifications"
></nana-radio>
</nana-radio-group> Horizontal
Section titled “Horizontal”Set orientation="horizontal" on the group.
<nana-radio-group
label="Billing period"
name="billing"
value="monthly"
orientation="horizontal"
>
<nana-radio value="monthly" label="Monthly"></nana-radio>
<nana-radio value="yearly" label="Yearly"></nana-radio>
<nana-radio value="lifetime" label="Lifetime"></nana-radio>
</nana-radio-group> Properties
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
checked | checked | boolean | false | Selected state (normally driven by nana-radio-group) |
description | description | string | undefined | — | Secondary descriptive text |
disabled | disabled | boolean | false | Disable the control |
groupDisabled | — | boolean | false | Set by a disabled radio group so the radio reports itself disabled. |
invalid | invalid | boolean | false | Invalid styling (set by the group when its validation fails) |
label | label | string | undefined | — | Convenience label text (slot wins if both are present) |
size | size | RadioSize | 'md' | Control size |
value | value | string | '' | Submitted / emitted value for this option |
Events
| Event | Description |
|---|---|
nana-change | Fired on selection (detail.value) |
Slots
| Slot | Description |
|---|---|
(default) | The label (overrides the label attribute) |
description | Secondary descriptive text |
CSS parts
| Part | Description |
|---|---|
::part(control) | The clickable row |
::part(circle) | The radio circle |
::part(label) | The label text |
::part(text) | The text |
::part(description) | The description |
CSS custom properties
| Property | Description |
|---|---|
--nana-radio-accent | Selected fill / border colour |
--nana-radio-dot-color | Inner dot colour |
--nana-radio-border | Unselected border colour |
--nana-radio-bg | Circle background |
--nana-radio-size | Circle diameter (overrides size preset) |
--nana-radio-radius | Corner radius of the control; fully round by default |
The attributes on the parent — value, name, orientation, size,
helper-text, error-message, required — belong to
Radio Group, which is what wires a radio into a
form. The button-styled alternative is
Radio Button.
NanaRadio
| Prop | Type |
|---|---|
valuerequired | string |
size | RadioSize |
label | string |
children | Snippet |
Also accepts Omit<HTMLInputAttributes, 'class' | 'size' | 'type' | 'value'>.
NanaRadioButton
| Prop | Type |
|---|---|
valuerequired | string |
size | RadioSize |
label | string |
prefix | Snippet |
children | Snippet |
Also accepts Omit<HTMLInputAttributes, 'class' | 'size' | 'type' | 'value' | 'prefix'>.
NanaRadioGroup
| Prop | Type | Default |
|---|---|---|
name | string | |
valuebind: | string | undefined |
size | RadioSize | 'md' |
orientation | RadioGroupOrientation | 'vertical' |
label | string | |
disabled | boolean | |
helperText | string | |
errorMessage | string | |
invalidbind: | boolean | false |
onValueChange | (value: string) => void | |
children | Snippet |
Also accepts Omit<HTMLAttributes<HTMLDivElement>, 'class'>.