Quaff

QRadio

Radio buttons select one option from a visible set of alternatives. Related buttons share a selected value and group name.

info QRadio API Source

interface QRadioProps extends HTMLAttributes<HTMLLabelElement>

disabled
?: boolean = false
When true, prevents user interaction with the radio button.

label
?: string = ""
Text label displayed next to the radio button.

name
?: string = undefined
Native name used to group radio buttons for keyboard navigation and form submission.

selected
?: QRadioValue = $bindable(undefined)
Bound value that determines if this radio button is selected. This prop is bindable. When using a group of radio buttons, this should be the same variable for all of them.

value
: QRadioValue = ""
Value associated with this radio button. Used when comparing against the selected value.

Usage

Basic Radio Buttons
QRadio buttons allow users to select a single option from a set. They're commonly used for exclusive selections where only one option can be chosen at a time.
Selected value: option1
Radio Groups
Radio buttons with the same selected binding and name form a group. This keeps their value, keyboard navigation, and native form behavior in sync.
Select your favorite fruit:
You selected: apple
Disabled State
Radio buttons can be disabled using the disabled prop. Disabled radio buttons cannot be interacted with and display with a muted appearance to indicate they're unavailable.
Two-way Binding
QRadio supports Svelte's two-way binding with the bind:selected directive. This makes it easy to track and update the selected value in your component's state.
Current selection: red
With List Items
Keep the radio as the only action, or make the whole item selectable when a larger target suits the interface.
Radio control
Option 1
First choice with description
Option 2
Second choice with description
Option 3
Third choice with description
Whole item
Option 1
First choice with description
Option 2
Second choice with description
Option 3
Third choice with description
Dynamic Radio Buttons
You can generate radio buttons dynamically from an array of options using Svelte's each block. This is useful when working with data-driven forms or when the options might change.
Favorite programming language:
You selected: Nothing yet
Event Handling
QRadio components support standard event handlers like onchange. This allows you to perform actions when the selection changes.
Accessibility
Give each group a shared name and an accessible label. Tab enters or leaves the group. Arrow keys move focus and immediately select the new option; Space selects the focused option, while Enter has no native radio action.
Notification method