Radio Button
Radios allow the user to select a single option from a group.
@volvo-cars/css v2.5.1@volvo-cars/react-forms v2.0.1
Radio Group With Hints
Section titled “Radio Group With Hints”Show code
import { Radio, RadioGroup } from '@volvo-cars/react-forms';
export function RadioGroupWithHints() { return ( <RadioGroup name="mileage" legend="Choose your mileage" defaultValue="6000" hint="Select the mileage for your subscription" > <Radio value="6000" label="6,000 km/yr" hint="500 km/month" /> <Radio value="8000" label="8,000 km/yr" hint="667 km/month" /> <Radio value="unlimited" label="Unlimited km/yr" hint="No monthly cap" /> </RadioGroup> );}Radio Group Controlled
Section titled “Radio Group Controlled”Show code
import { Radio, RadioGroup } from '@volvo-cars/react-forms';import { useState } from 'react';
export function RadioGroupControlled() { const [value, setValue] = useState('electric');
return ( <RadioGroup name="powertrain" legend="Powertrain" value={value} onChange={(e) => setValue(e.target.value)} > <Radio value="electric" label="Electric" /> <Radio value="hybrid" label="Hybrid" /> <Radio value="mild-hybrid" label="Mild hybrid" /> </RadioGroup> );}Radio Group Error
Section titled “Radio Group Error”Show code
import { Radio, RadioGroup } from '@volvo-cars/react-forms';
export function RadioGroupError() { return ( <RadioGroup name="terms-error" legend="Choose your terms" errorMessage="Please choose an option" > <Radio value="6000" label="6,000 km/yr" /> <Radio value="8000" label="8,000 km/yr" /> <Radio value="unlimited" label="Unlimited km/yr" /> </RadioGroup> );}Radio Custom Layout
Section titled “Radio Custom Layout”Show code
import { Radio, RadioContextProvider } from '@volvo-cars/react-forms';
export function RadioCustomLayout() { return ( <fieldset className="flex gap-16 flex-wrap"> <RadioContextProvider value={{ defaultValue: 'hybrid', name: 'engine', }} > <Radio value="electric" label="Electric" /> <Radio value="hybrid" label="Hybrid" /> <Radio value="mild-hybrid" label="Mild hybrid" /> </RadioContextProvider> </fieldset> );}CSS radio hints
Section titled “CSS radio hints”Show code
<fieldset class="flex-col stack-16"> <legend class="mb-4 font-medium">Choose your plan</legend> <div class="flex-row"> <input type="radio" name="plan" id="plan-basic" value="basic" /> <div class="flex-col stack-4 ml-8"> <label for="plan-basic">Basic</label> <span class="micro text-secondary">Includes 5 GB storage</span> </div> </div> <div class="flex-row"> <input type="radio" name="plan" id="plan-standard" value="standard" checked /> <div class="flex-col stack-4 ml-8"> <label for="plan-standard">Standard</label> <span class="micro text-secondary">Includes 50 GB storage</span> </div> </div> <div class="flex-row"> <input type="radio" name="plan" id="plan-premium" value="premium" /> <div class="flex-col stack-4 ml-8"> <label for="plan-premium">Premium</label> <span class="micro text-secondary">Includes unlimited storage</span> </div> </div></fieldset>CSS radio error
Section titled “CSS radio error”Show code
<fieldset class="flex-col stack-16" aria-invalid="true" aria-describedby="radio-error"> <legend class="font-medium mb-4">Choose your plan</legend> <span role="alert" id="radio-error" class="text-feedback-red micro" >Please select a plan</span > <div class="flex-row"> <input type="radio" name="plan-error" id="plan-error-a" value="basic" /> <label class="ml-8" for="plan-error-a">Basic</label> </div> <div class="flex-row"> <input type="radio" name="plan-error" id="plan-error-b" value="standard" /> <label class="ml-8" for="plan-error-b">Standard</label> </div> <div class="flex-row"> <input type="radio" name="plan-error" id="plan-error-c" value="premium" /> <label class="ml-8" for="plan-error-c">Premium</label> </div></fieldset>Custom CSS radio layout
Section titled “Custom CSS radio layout”Show code
<div class="flex gap-16 items-center"> <div class="flex-row"> <input type="radio" name="custom" id="custom-default" value="default" checked /> <label class="ml-8" for="custom-default">Default (no class)</label> </div> <div class="flex-row"> <input type="radio" class="radio my-custom-style" name="custom" id="custom-extended" value="extended" /> <label class="ml-8" for="custom-extended" >Extended (radio + custom class)</label > </div></div>