Trên trang này

Radio group

Ví dụ trực tiếp của Radio group, kèm đúng file Vue hiển thị từng ví dụ.

Mỗi ví dụ là một file Vue hoàn chỉnh. Chép vào ứng dụng đã cài registry, hoặc mở trong StackBlitz.

Chọn một

Luôn có một lựa chọn được chọn.

Khi sản phẩm hết hàng
RadioGroupBasic.vue
<script setup lang="ts">
import { ref } from 'vue'
import { Field, FieldLabel, FieldLegend, FieldSet } from '@/components/ui/field'
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'

const outOfStock = ref('sold-out')
</script>

<template>
  <FieldSet class="max-w-sm">
    <FieldLegend variant="label">Khi sản phẩm hết hàng</FieldLegend>
    <RadioGroup v-model="outOfStock">
      <Field orientation="horizontal">
        <RadioGroupItem id="oos-sold-out" value="sold-out" />
        <FieldLabel for="oos-sold-out">Hiện là đã bán hết</FieldLabel>
      </Field>
      <Field orientation="horizontal">
        <RadioGroupItem id="oos-hide" value="hide" />
        <FieldLabel for="oos-hide">Ẩn khỏi cửa hàng online</FieldLabel>
      </Field>
      <Field orientation="horizontal">
        <RadioGroupItem id="oos-backorder" value="backorder" />
        <FieldLabel for="oos-backorder">Vẫn bán, giao khi có hàng</FieldLabel>
      </Field>
    </RadioGroup>
  </FieldSet>
</template>

Có mô tả

Một dòng dưới mỗi lựa chọn giải thích nó.

Khi cùng một sản phẩm được sửa ở cả hai nơi
RadioGroupWithDescription.vue
<script setup lang="ts">
import { ref } from 'vue'
import { Field, FieldContent, FieldDescription, FieldLabel, FieldLegend, FieldSet } from '@/components/ui/field'
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'

const conflicts = [
  { value: 'erp', label: 'Theo ERP', description: 'Giá và tồn kho trong ERP ghi đè lên cửa hàng online.' },
  { value: 'store', label: 'Theo cửa hàng online', description: 'Thay đổi trong cửa hàng được gửi ngược về ERP.' },
  { value: 'ask', label: 'Hỏi tôi mỗi lần', description: 'Tác vụ đồng bộ tạm dừng sản phẩm đó cho tới khi có người chọn.' },
]
const winner = ref('erp')
</script>

<template>
  <FieldSet class="max-w-md">
    <FieldLegend variant="label">Khi cùng một sản phẩm được sửa ở cả hai nơi</FieldLegend>
    <RadioGroup v-model="winner">
      <Field v-for="option in conflicts" :key="option.value" orientation="horizontal">
        <RadioGroupItem :id="`conflict-${option.value}`" :value="option.value" :aria-describedby="`conflict-${option.value}-help`" />
        <FieldContent>
          <FieldLabel :for="`conflict-${option.value}`">{{ option.label }}</FieldLabel>
          <FieldDescription :id="`conflict-${option.value}-help`">{{ option.description }}</FieldDescription>
        </FieldContent>
      </Field>
    </RadioGroup>
  </FieldSet>
</template>

Lựa chọn chưa dùng được

Mô tả của nó nói lý do.

Cách giao hàng mặc định
RadioGroupDisabled.vue
<script setup lang="ts">
import { ref } from 'vue'
import { Field, FieldContent, FieldDescription, FieldLabel, FieldLegend, FieldSet } from '@/components/ui/field'
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'

// Một lựa chọn chưa dùng được; phần mô tả của nó nói vì sao.
const carrier = ref('standard')
</script>

<template>
  <FieldSet class="max-w-md">
    <FieldLegend variant="label">Cách giao hàng mặc định</FieldLegend>
    <RadioGroup v-model="carrier">
      <Field orientation="horizontal">
        <RadioGroupItem id="delivery-standard" value="standard" />
        <FieldLabel for="delivery-standard">Tiêu chuẩn, 3 đến 5 ngày</FieldLabel>
      </Field>
      <Field orientation="horizontal">
        <RadioGroupItem id="delivery-express" value="express" />
        <FieldLabel for="delivery-express">Nhanh, ngày hôm sau</FieldLabel>
      </Field>
      <Field orientation="horizontal" data-disabled="true">
        <RadioGroupItem id="delivery-same-day" value="same-day" disabled aria-describedby="delivery-same-day-help" />
        <FieldContent>
          <FieldLabel for="delivery-same-day">Trong ngày</FieldLabel>
          <FieldDescription id="delivery-same-day-help">Kết nối tài khoản đơn vị giao hàng trước.</FieldDescription>
        </FieldContent>
      </Field>
    </RadioGroup>
  </FieldSet>
</template>