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. Cả khung nhận viền focus khi ô bên trong có focus.
Tìm kiếm có icon và số đếm
Icon chỉ để trang trí. Ô được đặt tên bằng aria-label, và số đếm được đọc sau tên.
InputGroupSearch.vue
<script setup lang="ts">
import { Search } from '@lucide/vue'
import { computed, ref } from 'vue'
import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from '@/components/ui/input-group'
const orders = ['SO-1042 Kim khí Góc Phố', 'SO-1043 Tạp hóa Lá Xanh', 'SO-1044 Kim khí Góc Phố', 'SO-1045 Nhà sách Bến Xanh']
const query = ref('')
const count = computed(() => orders.filter(order => order.toLowerCase().includes(query.value.toLowerCase())).length)
</script>
<template>
<InputGroup class="max-w-sm">
<InputGroupAddon>
<Search aria-hidden="true" />
</InputGroupAddon>
<InputGroupInput v-model="query" type="search" aria-label="Tìm đơn hàng" aria-describedby="order-count" />
<InputGroupAddon align="inline-end">
<InputGroupText id="order-count" aria-live="polite">{{ count }} đơn hàng</InputGroupText>
</InputGroupAddon>
</InputGroup>
</template>Chữ cố định trước và sau
Chỉ dùng chữ không dấu, số và dấu gạch ngang.
InputGroupAddress.vue
<script setup lang="ts">
import { Field, FieldDescription, FieldLabel } from '@/components/ui/field'
import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from '@/components/ui/input-group'
</script>
<template>
<Field class="max-w-md">
<FieldLabel for="store-address">Địa chỉ cửa hàng</FieldLabel>
<InputGroup>
<InputGroupAddon>
<InputGroupText>https://</InputGroupText>
</InputGroupAddon>
<InputGroupInput id="store-address" default-value="kim-khi-goc-pho" aria-describedby="store-address-help" />
<InputGroupAddon align="inline-end">
<InputGroupText>.shop.example</InputGroupText>
</InputGroupAddon>
</InputGroup>
<FieldDescription id="store-address-help">Chỉ dùng chữ không dấu, số và dấu gạch ngang.</FieldDescription>
</Field>
</template>Nút bên trong: hiện mật khẩu
Nút chỉ có icon, được đặt tên bằng tooltip.
Mật khẩu của tài khoản ERP mà tác vụ đồng bộ dùng để đăng nhập.
InputGroupPassword.vue
<script setup lang="ts">
import { Eye, EyeOff } from '@lucide/vue'
import { ref } from 'vue'
import { Field, FieldDescription, FieldLabel } from '@/components/ui/field'
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from '@/components/ui/input-group'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
// Nút icon được tooltip đặt tên (relationship="label") và nói nút sẽ làm gì khi bấm.
const visible = ref(false)
</script>
<template>
<Field class="max-w-sm">
<FieldLabel for="erp-password">Mật khẩu ERP</FieldLabel>
<InputGroup>
<InputGroupInput id="erp-password" :type="visible ? 'text' : 'password'" autocomplete="current-password" aria-describedby="erp-password-help" />
<InputGroupAddon align="inline-end">
<TooltipProvider>
<Tooltip relationship="label">
<TooltipTrigger as-child>
<InputGroupButton size="icon-xs" @click="visible = !visible">
<EyeOff v-if="visible" />
<Eye v-else />
</InputGroupButton>
</TooltipTrigger>
<TooltipContent>{{ visible ? 'Ẩn mật khẩu' : 'Hiện mật khẩu' }}</TooltipContent>
</Tooltip>
</TooltipProvider>
</InputGroupAddon>
</InputGroup>
<FieldDescription id="erp-password-help">Mật khẩu của tài khoản ERP mà tác vụ đồng bộ dùng để đăng nhập.</FieldDescription>
</Field>
</template>Text area có số đếm và thao tác
align="block-end" đặt addon dưới phần chữ.
InputGroupReply.vue
<script setup lang="ts">
import { Send } from '@lucide/vue'
import { computed, ref } from 'vue'
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupText, InputGroupTextarea } from '@/components/ui/input-group'
const reply = ref('')
const left = computed(() => 500 - reply.value.length)
</script>
<template>
<InputGroup class="max-w-md">
<InputGroupTextarea v-model="reply" maxlength="500" aria-label="Trả lời khách hàng" aria-describedby="reply-left" />
<InputGroupAddon align="block-end">
<InputGroupText id="reply-left">Còn {{ left }} ký tự</InputGroupText>
<InputGroupButton variant="default" class="ml-auto">
<Send />Gửi trả lời
</InputGroupButton>
</InputGroupAddon>
</InputGroup>
</template>