Scroll area
A box that scrolls its contents, with slim scrollbars that match the theme.
Install
If this is the first component in the project, set up once. This writes ermine.json and copies the theme stylesheet. The installation guide covers Vue, Nuxt and Astro.
npx ermineui initpnpm dlx ermineui inityarn dlx ermineui initbunx ermineui initThen add the component:
npx ermineui add scroll-areapnpm dlx ermineui add scroll-areayarn dlx ermineui add scroll-areabunx ermineui add scroll-areaThat copies 2 files into src/components/ui/scroll-area/. Files you already have are kept.
Use
import { ScrollArea } from '@/components/ui/scroll-area'<script setup lang="ts">
import { ScrollArea } from '@/components/ui/scroll-area'
</script>
<template>
<ScrollArea />
</template>In Nuxt, with the auto-import setting, the tags work in templates without the import. In Astro, use it inside a Vue island. The props are documented in the source below, on each one.
What gets copied
| File | Where it goes |
|---|---|
ScrollArea.vue | src/components/ui/scroll-area/ScrollArea.vue |
index.ts | src/components/ui/scroll-area/index.ts |
The folders are the suggested ones. ermine.json says where yours are.
Source
This is exactly what the command copies. To install by hand, create each file below and the helpers listed above.
ScrollArea.vue 60 lines
<script setup lang="ts">
withDefaults(
defineProps<{
orientation?: 'vertical' | 'horizontal' | 'both'
/** What the box holds. Needed because it can be focused, to scroll with the keyboard. */
label: string
}>(),
{ orientation: 'vertical' },
)
</script>
<template>
<!-- Native scrolling throughout — touch, wheel, keyboard and find-in-page behave as usual. Only the bars are restyled. -->
<div class="er-scroll-area" role="region" tabindex="0" :aria-label="label" :data-orientation="orientation">
<slot />
</div>
</template>
<style>
@layer components {
.er-scroll-area {
max-width: 100%;
max-height: 100%;
border-radius: var(--er-radius-md);
overflow: hidden auto;
overscroll-behavior: contain;
scrollbar-width: thin;
scrollbar-color: var(--er-input) transparent;
}
.er-scroll-area[data-orientation='horizontal'] {
overflow: auto hidden;
}
.er-scroll-area[data-orientation='both'] {
overflow: auto;
}
.er-scroll-area:focus-visible {
outline: 2px solid var(--er-ring);
outline-offset: 2px;
}
/* Browsers without scrollbar-color (older Safari) get the same look from these. */
@supports not (scrollbar-color: auto) {
.er-scroll-area::-webkit-scrollbar {
width: 0.5rem;
height: 0.5rem;
}
.er-scroll-area::-webkit-scrollbar-thumb {
border: 2px solid transparent;
border-radius: 999px;
background: var(--er-input);
background-clip: content-box;
}
}
}
</style>index.ts 3 lines
/** Scroll area — a box that scrolls its contents, with slim scrollbars that match the theme. */
export { default as ScrollArea } from './ScrollArea.vue'