Trên trang này

Thanh cuộn

Ví dụ trực tiếp của Scroll area shadcn-vue, thanh cuộn dùng các token scrollbar.

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

Sản phẩm cần đồng bộ (40)
SKU-1000
SKU-1007
SKU-1014
SKU-1021
SKU-1028
SKU-1035
SKU-1042
SKU-1049
SKU-1056
SKU-1063
SKU-1070
SKU-1077
SKU-1084
SKU-1091
SKU-1098
SKU-1105
SKU-1112
SKU-1119
SKU-1126
SKU-1133
SKU-1140
SKU-1147
SKU-1154
SKU-1161
SKU-1168
SKU-1175
SKU-1182
SKU-1189
SKU-1196
SKU-1203
SKU-1210
SKU-1217
SKU-1224
SKU-1231
SKU-1238
SKU-1245
SKU-1252
SKU-1259
SKU-1266
SKU-1273
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>