Trên trang này

Ô nhập nhiều dòng

Ví dụ trực tiếp của Ô nhập nhiều dòng, 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. Ô cao dần khi gõ.

Nhãn, chữ hướng dẫn và giới hạn

Chữ hướng dẫn nói ghi chú hiện ở đâu và còn bao nhiêu ký tự.

TextareaWithHelp.vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import { Field, FieldDescription, FieldLabel } from '@/components/ui/field'
import { Textarea } from '@/components/ui/textarea'

const note = ref('')
const left = computed(() => 200 - note.value.length)
</script>

<template>
  <Field class="max-w-md">
    <FieldLabel for="slip-note">Ghi chú trên phiếu đóng gói</FieldLabel>
    <Textarea id="slip-note" v-model="note" maxlength="200" aria-describedby="slip-note-help" />
    <FieldDescription id="slip-note-help">In bên dưới các dòng hàng. Còn {{ left }} ký tự.</FieldDescription>
  </Field>
</template>

Lỗi

Lý do bắt buộc bị để trống. Gõ một lý do và lỗi biến mất.

TextareaInvalid.vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import { Field, FieldError, FieldLabel } from '@/components/ui/field'
import { Textarea } from '@/components/ui/textarea'

// Hiện sau khi người dùng đã bấm gửi: lý do là bắt buộc. Nhập một lý do để xóa lỗi.
const reason = ref('')
const invalid = computed(() => reason.value.trim().length === 0)
</script>

<template>
  <Field class="max-w-md" :data-invalid="invalid">
    <FieldLabel for="refund-reason">Lý do hoàn tiền</FieldLabel>
    <Textarea
      id="refund-reason"
      v-model="reason"
      :aria-invalid="invalid"
      :aria-describedby="invalid ? 'refund-reason-error' : undefined"
    />
    <FieldError v-if="invalid" id="refund-reason-error">Nhập lý do. Khách hàng sẽ thấy lý do này trong email hoàn tiền.</FieldError>
  </Field>
</template>