라디오 그룹
라디오 그룹 (RadioGroup)
라디오 그룹(RadioGroup)은 목록에서 하나의 옵션을 선택하는 라디오 버튼 묶음 컴포넌트예요. 목록·카드·테이블 등 여러 variant와 다양한 크기·색상을 지원해서 폼에서 많이 사용해요.
출처: Nuxt UI
본문
목록에서 하나의 옵션을 선택하는 라디오 버튼 묶음이에요.
사용법 (Usage)
v-model 디렉티브로 RadioGroup의 값을 제어하거나, 상태를 제어할 필요가 없을 때 default-value prop으로 초기값을 설정할 수 있어요.
<script setup lang="ts">
const items = ref([
"System",
"Light",
"Dark"
])
const value = ref("System")
</script>
<template>
<URadioGroup v-model="value" :items="items" />
</template>
Items (항목들)
items prop에 문자열이나 숫자 배열을 전달해요:
<script setup lang="ts">
const items = ref([
"System",
"Light",
"Dark"
])
const value = ref("System")
</script>
<template>
<URadioGroup v-model="value" :items="items" />
</template>
아래 속성들을 가진 객체 배열을 전달할 수도 있어요:
label?: stringdescription?: stringvalue?: stringdisabled?: booleanicon?: stringclass?: anyui?: { item?: ClassNameValue, container?: ClassNameValue, base?: ClassNameValue, 'indicator'?: ClassNameValue, wrapper?: ClassNameValue, label?: ClassNameValue, icon?: ClassNameValue, description?: ClassNameValue }
<script setup lang="ts">
import type { RadioGroupItem } from '@nuxt/ui'
const items = ref<RadioGroupItem[]>([
{
label: "System",
description: "Matches your device settings.",
value: "system"
},
{
label: "Light",
description: "Always uses the light theme.",
value: "light"
},
{
label: "Dark",
description: "Always uses the dark theme.",
value: "dark"
}
])
const value = ref("system")
</script>
<template>
<URadioGroup v-model="value" :items="items" />
</template>
[!CAUTION]
객체를 사용할 때는
v-model디렉티브나default-valueprop에서 객체의value속성을 참조해야 해요.
Value Key
value-key prop으로 값을 정하는 데 쓰는 속성을 바꿀 수 있어요. 기본값은 value예요.
<script setup lang="ts">
import type { RadioGroupItem } from '@nuxt/ui'
const items = ref<RadioGroupItem[]>([
{
label: "System",
description: "Matches your device settings.",
id: "system"
},
{
label: "Light",
description: "Always uses the light theme.",
id: "light"
},
{
label: "Dark",
description: "Always uses the dark theme.",
id: "dark"
}
])
const value = ref("light")
</script>
<template>
<URadioGroup v-model="value" value-key="id" :items="items" />
</template>
Legend (범례)
legend prop으로 RadioGroup의 범례를 설정할 수 있어요.
<script setup lang="ts">
const items = ref([
"System",
"Light",
"Dark"
])
</script>
<template>
<URadioGroup legend="Theme" default-value="System" :items="items" />
</template>
Color (색상)
color prop으로 RadioGroup의 색상을 바꿀 수 있어요.
<script setup lang="ts">
const items = ref([
"System",
"Light",
"Dark"
])
</script>
<template>
<URadioGroup color="neutral" default-value="System" :items="items" />
</template>
Variant (변형)
variant prop으로 RadioGroup의 변형을 바꿀 수 있어요.
<script setup lang="ts">
import type { RadioGroupItem } from '@nuxt/ui'
const items = ref<RadioGroupItem[]>([
{
label: "System",
value: "system",
description: "Matches your device settings."
},
{
label: "Light",
value: "light",
description: "Always uses the light theme."
},
{
label: "Dark",
value: "dark",
description: "Always uses the dark theme."
}
])
</script>
<template>
<URadioGroup color="primary" variant="card" default-value="system" :items="items" />
</template>
Size (크기)
size prop으로 RadioGroup의 크기를 바꿀 수 있어요.
<script setup lang="ts">
const items = ref([
"System",
"Light",
"Dark"
])
</script>
<template>
<URadioGroup size="xl" variant="list" default-value="System" :items="items" />
</template>
Orientation (배치 방향)
orientation prop으로 RadioGroup의 배치 방향을 바꿀 수 있어요. 기본값은 vertical이에요.
<script setup lang="ts">
const items = ref([
"System",
"Light",
"Dark"
])
</script>
<template>
<URadioGroup orientation="horizontal" variant="list" default-value="System" :items="items" />
</template>
Indicator (표시자)
indicator prop으로 표시자의 위치를 바꾸거나 숨길 수 있어요. 기본값은 start예요.
[!NOTE]
항목의
icon은indicator가hidden일 때만 라벨 위에 표시돼요. 라디오의 표시자 안에는 아이콘을 넣을 수 없기 때문이에요.
<script setup lang="ts">
import type { RadioGroupItem } from '@nuxt/ui'
const items = ref<RadioGroupItem[]>([
{
label: "System",
icon: "i-lucide-monitor",
value: "System",
class: "w-20"
},
{
label: "Light",
icon: "i-lucide-sun",
value: "Light",
class: "w-20"
},
{
label: "Dark",
icon: "i-lucide-moon",
value: "Dark",
class: "w-20"
}
])
</script>
<template>
<URadioGroup indicator="hidden" orientation="horizontal" variant="table" default-value="System" :items="items" />
</template>
Disabled (비활성화)
disabled prop으로 RadioGroup을 비활성화할 수 있어요.
<script setup lang="ts">
const items = ref([
"System",
"Light",
"Dark"
])
</script>
<template>
<URadioGroup disabled default-value="System" :items="items" />
</template>
API
Props
/**
* Props for the RadioGroup component
*/
interface RadioGroupProps {
/**
* The element or component this component should render as.
* @default 'div'
*/
as?: any;
legend?: string | undefined;
/**
* When `items` is an array of objects, select the field to use as the value.
* @default 'value'
*/
valueKey?: VK | undefined;
/**
* When `items` is an array of objects, select the field to use as the label.
* @default 'label'
*/
labelKey?: keyof Extract<NestedItem<T>, object> & string | DotPathKeys<Extract<NestedItem<T>, object>> | undefined;
/**
* When `items` is an array of objects, select the field to use as the description.
* @default 'description'
*/
descriptionKey?: keyof Extract<NestedItem<T>, object> & string | DotPathKeys<Extract<NestedItem<T>, object>> | undefined;
items?: T | undefined;
/**
* The controlled value of the RadioGroup. Can be bind as `v-model`.
*/
modelValue?: GetItemValue<T, VK, undefined, NestedItem<T>> | undefined;
/**
* The value of the RadioGroup when initially rendered. Use when you do not need to control the state of the RadioGroup.
*/
defaultValue?: GetItemValue<T, VK, undefined, NestedItem<T>> | undefined;
/**
* @default 'md'
*/
size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
/**
* @default 'list'
*/
variant?: "card" | "list" | "table" | undefined;
/**
* @default 'primary'
*/
color?: "primary" | "secondary" | "success" | "info" | "warning" | "error" | "neutral" | undefined;
/**
* Highlight the ring color like a focus state.
* @default false
*/
highlight?: boolean | undefined;
/**
* The orientation the radio buttons are laid out.
* @default 'vertical'
*/
orientation?: "horizontal" | "vertical" | undefined;
/**
* Position of the indicator.
* @default 'start'
*/
indicator?: "start" | "end" | "hidden" | undefined;
ui?: { root?: SlotClass; fieldset?: SlotClass; legend?: SlotClass; item?: SlotClass; container?: SlotClass; base?: SlotClass; indicator?: SlotClass; wrapper?: SlotClass; label?: SlotClass; icon?: SlotClass; description?: SlotClass; } | undefined;
/**
* When `true`, prevents the user from interacting with radio items.
*/
disabled?: boolean | undefined;
/**
* When `true`, keyboard navigation will loop from last item to first, and vice versa.
*/
loop?: boolean | undefined;
/**
* The name of the field. Submitted with its owning form as part of a name/value pair.
*/
name?: string | undefined;
/**
* When `true`, indicates that the user must set the value before the owning form can be submitted.
*/
required?: boolean | undefined;
}
Slots
/**
* Slots for the RadioGroup component
*/
interface RadioGroupSlots {
legend(): any;
label(): any;
description(): any;
}
Emits
/**
* Emitted events for the RadioGroup component
*/
interface RadioGroupEmits {
update:modelValue: (payload: [value: GetItemValue<T, VK, undefined, NestedItem<T>>]) => void;
change: (payload: [event: Event]) => void;
}
테마 (Theme)
export default defineAppConfig({
ui: {
radioGroup: {
slots: {
root: 'relative',
fieldset: 'flex gap-x-2',
legend: 'mb-1 block font-medium text-default',
item: 'flex items-start',
container: 'flex items-center',
base: 'rounded-full ring ring-inset ring-accented overflow-hidden focus-visible:outline-none',
indicator: 'flex items-center justify-center size-full after:bg-default after:rounded-full',
wrapper: 'w-full',
label: 'block font-medium text-default',
icon: 'shrink-0',
description: 'text-muted'
},
variants: {
color: {
primary: {
indicator: 'bg-primary'
},
secondary: {
indicator: 'bg-secondary'
},
success: {
indicator: 'bg-success'
},
info: {
indicator: 'bg-info'
},
warning: {
indicator: 'bg-warning'
},
error: {
indicator: 'bg-error'
},
neutral: {
indicator: 'bg-inverted'
}
},
variant: {
list: {
fieldset: 'flex-wrap',
item: ''
},
card: {
fieldset: 'flex-wrap',
item: [
'border border-default rounded-lg hover:not-has-disabled:not-has-focus-visible:not-has-data-[state=checked]:bg-elevated/50',
'transition-colors'
]
},
table: {
item: [
'border border-default hover:not-has-disabled:not-has-focus-visible:not-has-data-[state=checked]:bg-elevated/50',
'transition-colors'
]
}
},
orientation: {
horizontal: {
fieldset: 'flex-row'
},
vertical: {
fieldset: 'flex-col'
}
},
indicator: {
start: {
item: 'flex-row',
wrapper: 'ms-2'
},
end: {
item: 'flex-row-reverse',
wrapper: 'me-2'
},
hidden: {
base: 'sr-only',
wrapper: 'flex flex-col items-center gap-1 text-center'
}
},
size: {
xs: {
fieldset: 'gap-y-0.5',
legend: 'text-xs',
base: 'size-3',
item: 'text-xs',
container: 'h-4',
indicator: 'after:size-1'
},
sm: {
fieldset: 'gap-y-0.5',
legend: 'text-xs',
base: 'size-3.5',
item: 'text-xs',
container: 'h-4',
indicator: 'after:size-1'
},
md: {
fieldset: 'gap-y-1',
legend: 'text-sm',
base: 'size-4',
item: 'text-sm',
container: 'h-5',
indicator: 'after:size-1.5'
},
lg: {
fieldset: 'gap-y-1',
legend: 'text-sm',
base: 'size-4.5',
item: 'text-sm',
container: 'h-5',
indicator: 'after:size-1.5'
},
xl: {
fieldset: 'gap-y-1.5',
legend: 'text-base',
base: 'size-5',
item: 'text-base',
container: 'h-6',
indicator: 'after:size-2'
}
},
highlight: {
true: '',
false: ''
},
disabled: {
true: {
item: 'opacity-75',
base: 'cursor-not-allowed',
label: 'cursor-not-allowed',
description: 'cursor-not-allowed'
}
},
required: {
true: {
legend: "after:content-['*'] after:ms-0.5 after:text-error"
}
}
},
compoundVariants: [
{
indicator: 'hidden',
class: {
container: 'h-auto'
}
},
{
variant: [
'card',
'table'
],
highlight: false,
class: {
item: 'hover:not-has-disabled:not-has-focus-visible:not-has-data-[state=checked]:border-accented hover:not-has-disabled:not-has-focus-visible:not-has-data-[state=checked]:z-[1]'
}
},
{
size: 'xs',
indicator: 'hidden',
class: {
icon: 'size-3'
}
},
{
size: 'sm',
indicator: 'hidden',
class: {
icon: 'size-3.5'
}
},
{
size: 'md',
indicator: 'hidden',
class: {
icon: 'size-4'
}
},
{
size: 'lg',
indicator: 'hidden',
class: {
icon: 'size-4.5'
}
},
{
size: 'xl',
indicator: 'hidden',
class: {
icon: 'size-5'
}
},
{
size: 'xs',
variant: [
'card',
'table'
],
class: {
item: 'p-2.5'
}
},
{
size: 'sm',
variant: [
'card',
'table'
],
class: {
item: 'p-3'
}
},
{
size: 'md',
variant: [
'card',
'table'
],
class: {
item: 'p-3.5'
}
},
{
size: 'lg',
variant: [
'card',
'table'
],
class: {
item: 'p-4'
}
},
{
size: 'xl',
variant: [
'card',
'table'
],
class: {
item: 'p-4.5'
}
},
{
orientation: 'horizontal',
variant: 'table',
class: {
item: 'first-of-type:rounded-s-lg last-of-type:rounded-e-lg',
fieldset: 'gap-0 -space-x-px'
}
},
{
orientation: 'vertical',
variant: 'table',
class: {
item: 'first-of-type:rounded-t-lg last-of-type:rounded-b-lg',
fieldset: 'gap-0 -space-y-px'
}
},
{
color: 'primary',
variant: 'list',
indicator: [
'start',
'end'
],
class: {
base: 'outline-primary/25 focus-visible:outline-solid focus-visible:outline-3 focus-visible:ring-primary'
}
},
{
color: 'secondary',
variant: 'list',
indicator: [
'start',
'end'
],
class: {
base: 'outline-secondary/25 focus-visible:outline-solid focus-visible:outline-3 focus-visible:ring-secondary'
}
},
{
color: 'success',
variant: 'list',
indicator: [
'start',
'end'
],
class: {
base: 'outline-success/25 focus-visible:outline-solid focus-visible:outline-3 focus-visible:ring-success'
}
},
{
color: 'info',
variant: 'list',
indicator: [
'start',
'end'
],
class: {
base: 'outline-info/25 focus-visible:outline-solid focus-visible:outline-3 focus-visible:ring-info'
}
},
{
color: 'warning',
variant: 'list',
indicator: [
'start',
'end'
],
class: {
base: 'outline-warning/25 focus-visible:outline-solid focus-visible:outline-3 focus-visible:ring-warning'
}
},
{
color: 'error',
variant: 'list',
indicator: [
'start',
'end'
],
class: {
base: 'outline-error/25 focus-visible:outline-solid focus-visible:outline-3 focus-visible:ring-error'
}
},
{
color: 'neutral',
variant: 'list',
indicator: [
'start',
'end'
],
class: {
base: 'outline-inverted/25 focus-visible:outline-solid focus-visible:outline-3 focus-visible:ring-inverted'
}
},
{
color: 'primary',
variant: [
'card',
'table'
],
class: {
item: 'outline-primary/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-primary has-focus-visible:z-[1]'
}
},
{
color: 'secondary',
variant: [
'card',
'table'
],
class: {
item: 'outline-secondary/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-secondary has-focus-visible:z-[1]'
}
},
{
color: 'success',
variant: [
'card',
'table'
],
class: {
item: 'outline-success/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-success has-focus-visible:z-[1]'
}
},
{
color: 'info',
variant: [
'card',
'table'
],
class: {
item: 'outline-info/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-info has-focus-visible:z-[1]'
}
},
{
color: 'warning',
variant: [
'card',
'table'
],
class: {
item: 'outline-warning/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-warning has-focus-visible:z-[1]'
}
},
{
color: 'error',
variant: [
'card',
'table'
],
class: {
item: 'outline-error/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-error has-focus-visible:z-[1]'
}
},
{
color: 'neutral',
variant: [
'card',
'table'
],
class: {
item: 'outline-inverted/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-inverted has-focus-visible:z-[1]'
}
},
{
color: 'primary',
variant: 'list',
indicator: 'hidden',
class: {
item: 'outline-primary/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-primary has-focus-visible:z-[1]'
}
},
{
color: 'secondary',
variant: 'list',
indicator: 'hidden',
class: {
item: 'outline-secondary/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-secondary has-focus-visible:z-[1]'
}
},
{
color: 'success',
variant: 'list',
indicator: 'hidden',
class: {
item: 'outline-success/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-success has-focus-visible:z-[1]'
}
},
{
color: 'info',
variant: 'list',
indicator: 'hidden',
class: {
item: 'outline-info/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-info has-focus-visible:z-[1]'
}
},
{
color: 'warning',
variant: 'list',
indicator: 'hidden',
class: {
item: 'outline-warning/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-warning has-focus-visible:z-[1]'
}
},
{
color: 'error',
variant: 'list',
indicator: 'hidden',
class: {
item: 'outline-error/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-error has-focus-visible:z-[1]'
}
},
{
color: 'neutral',
variant: 'list',
indicator: 'hidden',
class: {
item: 'outline-inverted/25 has-focus-visible:outline-3 not-has-disabled:has-focus-visible:border-inverted has-focus-visible:z-[1]'
}
},
{
color: 'primary',
variant: 'card',
class: {
item: 'has-data-[state=checked]:border-primary/50 has-data-[state=checked]:bg-primary/10'
}
},
{
color: 'secondary',
variant: 'card',
class: {
item: 'has-data-[state=checked]:border-secondary/50 has-data-[state=checked]:bg-secondary/10'
}
},
{
color: 'success',
variant: 'card',
class: {
item: 'has-data-[state=checked]:border-success/50 has-data-[state=checked]:bg-success/10'
}
},
{
color: 'info',
variant: 'card',
class: {
item: 'has-data-[state=checked]:border-info/50 has-data-[state=checked]:bg-info/10'
}
},
{
color: 'warning',
variant: 'card',
class: {
item: 'has-data-[state=checked]:border-warning/50 has-data-[state=checked]:bg-warning/10'
}
},
{
color: 'error',
variant: 'card',
class: {
item: 'has-data-[state=checked]:border-error/50 has-data-[state=checked]:bg-error/10'
}
},
{
color: 'neutral',
variant: 'card',
class: {
item: 'has-data-[state=checked]:border-inverted/50 has-data-[state=checked]:bg-elevated'
}
},
{
color: 'primary',
variant: 'table',
class: {
item: 'has-data-[state=checked]:bg-primary/10 has-data-[state=checked]:border-primary/50 has-data-[state=checked]:z-[2]'
}
},
{
color: 'secondary',
variant: 'table',
class: {
item: 'has-data-[state=checked]:bg-secondary/10 has-data-[state=checked]:border-secondary/50 has-data-[state=checked]:z-[2]'
}
},
{
color: 'success',
variant: 'table',
class: {
item: 'has-data-[state=checked]:bg-success/10 has-data-[state=checked]:border-success/50 has-data-[state=checked]:z-[2]'
}
},
{
color: 'info',
variant: 'table',
class: {
item: 'has-data-[state=checked]:bg-info/10 has-data-[state=checked]:border-info/50 has-data-[state=checked]:z-[2]'
}
},
{
color: 'warning',
variant: 'table',
class: {
item: 'has-data-[state=checked]:bg-warning/10 has-data-[state=checked]:border-warning/50 has-data-[state=checked]:z-[2]'
}
},
{
color: 'error',
variant: 'table',
class: {
item: 'has-data-[state=checked]:bg-error/10 has-data-[state=checked]:border-error/50 has-data-[state=checked]:z-[2]'
}
},
{
color: 'neutral',
variant: 'table',
class: {
item: 'has-data-[state=checked]:bg-elevated has-data-[state=checked]:border-inverted/50 has-data-[state=checked]:z-[2]'
}
},
{
variant: [
'card',
'table'
],
disabled: true,
class: {
item: 'cursor-not-allowed'
}
},
{
color: 'primary',
indicator: 'hidden',
highlight: true,
class: {
item: 'not-has-disabled:border-primary not-has-disabled:has-data-[state=checked]:border-primary'
}
},
{
color: 'secondary',
indicator: 'hidden',
highlight: true,
class: {
item: 'not-has-disabled:border-secondary not-has-disabled:has-data-[state=checked]:border-secondary'
}
},
{
color: 'success',
indicator: 'hidden',
highlight: true,
class: {
item: 'not-has-disabled:border-success not-has-disabled:has-data-[state=checked]:border-success'
}
},
{
color: 'info',
indicator: 'hidden',
highlight: true,
class: {
item: 'not-has-disabled:border-info not-has-disabled:has-data-[state=checked]:border-info'
}
},
{
color: 'warning',
indicator: 'hidden',
highlight: true,
class: {
item: 'not-has-disabled:border-warning not-has-disabled:has-data-[state=checked]:border-warning'
}
},
{
color: 'error',
indicator: 'hidden',
highlight: true,
class: {
item: 'not-has-disabled:border-error not-has-disabled:has-data-[state=checked]:border-error'
}
},
{
color: 'neutral',
indicator: 'hidden',
highlight: true,
class: {
item: 'not-has-disabled:border-inverted not-has-disabled:has-data-[state=checked]:border-inverted'
}
},
{
color: 'primary',
highlight: true,
class: {
base: 'ring-primary'
}
},
{
color: 'secondary',
highlight: true,
class: {
base: 'ring-secondary'
}
},
{
color: 'success',
highlight: true,
class: {
base: 'ring-success'
}
},
{
color: 'info',
highlight: true,
class: {
base: 'ring-info'
}
},
{
color: 'warning',
highlight: true,
class: {
base: 'ring-warning'
}
},
{
color: 'error',
highlight: true,
class: {
base: 'ring-error'
}
},
{
color: 'neutral',
highlight: true,
class: {
base: 'ring-inverted'
}
}
],
defaultVariants: {
highlight: false,
size: 'md',
color: 'primary',
variant: 'list',
indicator: 'start'
}
}
}
})
변경 기록 (Changelog)
더 알아보기 (Learn more)
- RadioGroup — 접근성과 동작의 기반이 되는 Reka UI 문서
- GitHub 소스
- 전체 사이트맵