Mục lục tham khảo

Thành phần

Radio Group

Pick one option on Base UI RadioGroup and Radio; selected is an ink fill with a paper dot.

Nội dung tham khảo viết bằng tiếng Anh; mục “Vietnamese” có ví dụ tiếng Việt.

Xem trước

Delivery

Install

bash

npx shadcn add @eloquent/radio-group

Usage

tsx

import { Label } from "@/components/ui/label";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";

<span id="delivery-legend" className="kicker">Delivery</span>
<RadioGroup aria-labelledby="delivery-legend" name="delivery" defaultValue="morning">
  <Label><RadioGroupItem value="morning" />Morning edition</Label>
  <Label><RadioGroupItem value="evening" />Evening edition</Label>
</RadioGroup>

Label the group with aria-labelledby (or a FieldSet and FieldLegend) and each item with a wrapping Label.

States

StateTreatment
UnselectedPaper fill, 1px ink border
SelectedSolid ink fill and a paper dot
Focus2px ink outline, 2px offset
Invalid2px ink border, plus the Field's rule and message
DisabledHalftone border and dot, cursor-not-allowed

Keyboard

KeyAction
Tab / Shift+TabEnter the group on the selected item (or the first), and leave it
Arrow Down / RightMove focus to the next item and select it
Arrow Up / LeftMove focus to the previous item and select it
SpaceSelect the focused item

A disabled group keeps its selected item focusable (Base UI behaviour) but nothing can change.

Vietnamese

Phương thức nhận tin

Ink adaptation

Upstream shadcn's round container, shadow and ring glow are removed: the box is square (radius is 0) and only the dot is a circle. The 20px box sits in a 44px pointer target built from an ::after layer. There is no hover treatment. Built on Base UI RadioGroup and Radio.