shadcn-templ 2.0 beta. Switch to templUI v1
1.7k

Radio Group

A set of checkable buttons, known as radio buttons, where no more than one of the buttons can be checked at a time.

package examples import (

Installation

shadcn-templ add radio-group

Usage

import (	"github.com/axadrn/shadcn-templ/v2/components/label"	"github.com/axadrn/shadcn-templ/v2/components/radio")
@radiogroup.RadioGroup(radiogroup.Props{Value: "option-one"}) {	<div class="flex items-center gap-3">		@radiogroup.Item(radiogroup.ItemProps{ID: "option-one", Value: "option-one"})		@label.Label(label.Props{For: "option-one"}) {			Option One		}	</div>	<div class="flex items-center gap-3">		@radiogroup.Item(radiogroup.ItemProps{ID: "option-two", Value: "option-two"})		@label.Label(label.Props{For: "option-two"}) {			Option Two		}	</div>}

Composition

Use the following composition to build a RadioGroup:

radiogroup.RadioGroup├── radiogroup.Item└── radiogroup.Item

Description

Radio group items with a description using the Field component.

Standard spacing for most use cases.

More space between elements.

Minimal spacing for dense layouts.

package examples import (

Choice Card

Use field.Label to wrap the entire field.Field for a clickable card-style selection.

package examples import (

Fieldset

Use field.Set and field.Legend to group radio items with a label and description.

Subscription Plan

Yearly and lifetime plans offer significant savings.

package examples import (

Disabled

Use the Disabled prop on radiogroup.RadioGroup to disable all items.

package examples import (

Invalid

Use aria-invalid on radiogroup.Item and Invalid on field.Field to show validation errors.

Notification Preferences

Choose how you want to receive notifications.

package examples import (

API Reference

RadioGroup

The radiogroup.RadioGroup component shares the name and the selected value with its items.

Prop Type Default
Name string random
Value string -
Disabled bool false
Class string -

RadioGroupItem

The radiogroup.Item component is a single radio button with a hidden native input.

Prop Type Default
Name string group
Value string -
Checked bool false
Disabled bool false
Form string -
Class string -