रेडियो समूह
योजनाओं, शिपिंग विकल्पों और सेटिंग्स फ़ॉर्म के लिए एकल-चयन रेडियो बटन का सेट — नियोब्रूटलिस्ट बॉर्डर-और-छाया उपचार के साथ।
import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
रेडियो ग्रुप परस्पर अनन्य विकल्पों का एक सेट सामने रखता है — कोई एक आइटम चेक करते ही बाक़ी अपने आप अनचेक हो जाते हैं। यह Base UI Radio Group कंपोनेंट पर बना है और नियोब्रूटलिस्ट रेसिपी के अनुसार स्टाइल किया गया है: मोटे बॉर्डर, कठोर छायाएँ और बोल्ड टाइपोग्राफ़ी।
इसे इन स्थितियों में चुनें:
- प्लान पिकर — free / pro / enterprise को चॉइस कार्ड की तरह दिखाएँ, जहाँ चयन एक ही रहे।
- चेकआउट विकल्प — शिपिंग स्पीड या पेमेंट मेथड, जहाँ हर विकल्प सामने दिखता रहना चाहिए।
- 2–5 विकल्पों वाली सेटिंग्स — थीम, डेंसिटी, नोटिफ़िकेशन फ़्रीक्वेंसी; सेलेक्ट से कम क्लिक में काम हो जाता है।
इंस्टॉलेशन#
pnpm dlx shadcn@latest add https://neobrutalism.com/r/base/radio-group.jsonnpx shadcn@latest add https://neobrutalism.com/r/base/radio-group.jsonyarn dlx shadcn@latest add https://neobrutalism.com/r/base/radio-group.jsonbunx --bun shadcn@latest add https://neobrutalism.com/r/base/radio-group.json
निम्नलिखित डिपेंडेंसी इंस्टॉल करें:
pnpm add @base-ui/reactnpm install @base-ui/reactyarn add @base-ui/reactbun add @base-ui/react
निम्नलिखित कोड को अपने प्रोजेक्ट में कॉपी और पेस्ट करें.
"use client"
import * as React from "react"
import { RadioGroup as RadioGroupPrimitive } from "radix-ui"
import { cn } from "@/lib/utils"
function RadioGroup({
className,
...props
}: React.ComponentProps<typeof RadioGroupPrimitive.Root>) {
return (
<RadioGroupPrimitive.Root
data-slot="radio-group"
className={cn("grid w-full gap-2", className)}
{...props}
/>
)
}
function RadioGroupItem({
className,
...props
}: React.ComponentProps<typeof RadioGroupPrimitive.Item>) {
return (
<RadioGroupPrimitive.Item
data-slot="radio-group-item"
className={cn(
"group/radio-group-item peer relative flex aspect-square size-5 shrink-0 rounded-full border-2 bg-input shadow-sm outline-none after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive",
className
)}
{...props}
>
<RadioGroupPrimitive.Indicator
data-slot="radio-group-indicator"
className="flex size-4 items-center justify-center"
>
<span className="absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary" />
</RadioGroupPrimitive.Indicator>
</RadioGroupPrimitive.Item>
)
}
export { RadioGroup, RadioGroupItem }
अपने प्रोजेक्ट सेटअप के अनुसार इंपोर्ट पाथ अपडेट करें.
उपयोग#
import { Label } from "@/components/ui/label"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"<RadioGroup defaultValue="option-one">
<div className="flex items-center gap-3">
<RadioGroupItem value="option-one" id="option-one" />
<Label htmlFor="option-one">Option One</Label>
</div>
<div className="flex items-center gap-3">
<RadioGroupItem value="option-two" id="option-two" />
<Label htmlFor="option-two">Option Two</Label>
</div>
</RadioGroup>कंपोज़िशन#
RadioGroup बनाने के लिए निम्नलिखित कंपोज़िशन का उपयोग करें:
RadioGroup
├── RadioGroupItem
└── RadioGroupItemउदाहरण#
विवरण#
Field कंपोनेंट की मदद से विवरण के साथ रेडियो ग्रुप आइटम.
import {
Field,
FieldContent,Choice Card#
क्लिक करने योग्य कार्ड-शैली के चयन के लिए पूरे Field को लपेटने हेतु FieldLabel का उपयोग करें.
import {
Field,
FieldContent,Fieldset#
रेडियो आइटम को लेबल और विवरण के साथ समूहित करने के लिए FieldSet और FieldLegend का उपयोग करें.
import {
Field,
FieldDescription,अक्षम#
सभी आइटम को अक्षम करने के लिए RadioGroup पर disabled prop का उपयोग करें.
import { Field, FieldLabel } from "@/components/ui/field"
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"
अमान्य#
वैलिडेशन एरर दिखाने के लिए RadioGroupItem पर aria-invalid और Field पर data-invalid का उपयोग करें.
import {
Field,
FieldDescription,RTL#
Neobrutalism में RTL समर्थन सक्षम करने के लिए, RTL कॉन्फ़िगरेशन गाइड देखें.
"use client"
import * as React from "react"एक्सेसिबिलिटी#
रेडियो ग्रुप WAI-ARIA Radio Group पैटर्न का पालन करता है: कंटेनर role="radiogroup" रेंडर करता है, हर आइटम aria-checked वाला role="radio" बटन होता है, और रोविंग tabindex पूरे ग्रुप को एक ही टैब स्टॉप बनाए रखता है।
कीबोर्ड इंटरैक्शन:
| कुंजी | क्रिया |
|---|---|
Tab / Shift + Tab | फ़ोकस ग्रुप के भीतर (चेक किए गए आइटम पर, वरना पहले आइटम पर) लाएँ / बाहर ले जाएँ |
Space | फ़ोकस किया गया आइटम पहले से चेक न हो तो उसे चेक करें |
ArrowDown / ArrowRight | फ़ोकस अगले आइटम पर ले जाएँ और उसे चेक करें |
ArrowUp / ArrowLeft | फ़ोकस पिछले आइटम पर ले जाएँ और उसे चेक करें |
RTL में बाएँ और दाएँ एरो पढ़ने की दिशा के अनुसार चलते हैं।
API रेफ़रेंस#
Base UI Radio Group दस्तावेज़ देखें.