Phần lớn vùng cuộn không cần component: CSS thanh cuộn gốc ở tab Code đã tạo style cho chúng. Dùng Scroll area khi cần Vue vẽ thanh cuộn, ví dụ để giữ giống nhau trên mọi hệ điều hành. Cài bằng npx shadcn-vue@latest add https://beehexa.design/r/scroll-area.json.
Danh sách dài
ScrollAreaList.vue
<script setup lang="ts">
import { ScrollArea } from '@/components/ui/scroll-area'
import { Separator } from '@/components/ui/separator'
const skus = Array.from({ length: 40 }, (_, i) => `SKU-${String(1000 + i * 7)}`)
</script>
<template>
<!-- Chiều cao có giới hạn; thanh cuộn hiện khi con trỏ ở trên vùng này. Trong danh sách không có gì nhận focus,
nên chính danh sách nhận focus (tabindex, để cuộn bằng phím mũi tên) và có tên. -->
<ScrollArea class="h-56 w-full max-w-60 rounded-(--bh-radius-card) border-(length:--bh-border-width-default) border-(--bh-color-border) bg-(--bh-color-surface)">
<div tabindex="0" role="region" aria-label="Sản phẩm cần đồng bộ" class="p-(--bh-space-150) [font:var(--bh-font-body-default)] text-(--bh-color-text)">
<div class="mb-(--bh-space-100) [font:var(--bh-font-heading-xsmall)]">Sản phẩm cần đồng bộ (40)</div>
<template v-for="(sku, index) in skus" :key="sku">
<Separator v-if="index > 0" class="my-(--bh-space-100)" />
<div class="[font:var(--bh-font-code-default)]">{{ sku }}</div>
</template>
</div>
</ScrollArea>
</template>Cuộn ngang
ScrollAreaHorizontal.vue
<script setup lang="ts">
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area'
const channels = ['Cửa hàng online', 'Bán tại quầy', 'Sàn thương mại', 'ERP', 'CRM', 'Kho hàng']
</script>
<template>
<!-- Thanh cuộn ngang: thêm <ScrollBar orientation="horizontal" />. Các thẻ là link, nên người dùng bàn phím tới được bằng Tab. -->
<ScrollArea class="w-full max-w-120 whitespace-nowrap rounded-(--bh-radius-card) border-(length:--bh-border-width-default) border-(--bh-color-border) bg-(--bh-color-surface)">
<div class="flex w-max gap-(--bh-space-150) p-(--bh-space-150)">
<a
v-for="channel in channels"
:key="channel"
href="#channel"
class="flex h-(--bh-space-1000) w-40 shrink-0 items-end rounded-(--bh-radius-card) bg-(--bh-color-surface-subtle) p-(--bh-space-150) text-(--bh-color-text) [font:var(--bh-font-label-default)] no-underline outline-none focus-visible:outline-solid focus-visible:outline-(length:--bh-border-width-focused) focus-visible:outline-(color:--bh-color-border-focus) focus-visible:-outline-offset-(--bh-border-width-focused)"
>{{ channel }}</a>
</div>
<ScrollBar orientation="horizontal" />
</ScrollArea>
</template>