Usage
The ScrollArea component creates scrollable containers with optional virtualization for large lists.
Items
Use the items prop as an array and render each item using the default slot:
items prop to render custom scrollable content directly.Orientation
Use the orientation prop to change the scroll direction. Defaults to vertical.
Virtualize
Use the virtualize prop to render only the items currently in view, significantly boosting performance when working with large datasets.
virtualize prop options like gap, paddingStart, and paddingEnd. Otherwise, use the ui prop to apply classes like gap p-4 on the viewport slot.Examples
As masonry layout
Use the virtualize prop with lanes, gap, and estimateSize options to create Pinterest-style masonry layouts with variable height items.
estimateSize close to your average item height. Increasing overscan improves scrolling smoothness but renders more off-screen items.With responsive lanes
You can use the useWindowSize (for viewport-based) or useElementSize (for container-based) composables to make the lanes reactive.
With programmatic scroll
You can use the exposed virtualizer to programmatically control scroll position.
With infinite scroll
You can use the useInfiniteScroll composable to load more data as the user scrolls.
With default slot
You can use the default slot without the items prop to render custom scrollable content directly.
API
Props
Slots
Emits
Expose
You can access the typed component instance using useTemplateRef.
<script setup lang="ts">
const scrollArea = useTemplateRef('scrollArea')
// Scroll to a specific item
function scrollToItem(index: number) {
scrollArea.value?.virtualizer?.scrollToIndex(index, { align: 'center' })
}
</script>
<template>
<B24ScrollArea ref="scrollArea" :items="items" virtualize />
</template>
This will give you access to the following:
Theme
export default defineAppConfig({
b24ui: {
scrollArea: {
slots: {
root: 'relative',
viewport: 'relative flex',
item: ''
},
variants: {
orientation: {
vertical: {
root: 'overflow-y-auto overflow-x-hidden',
viewport: 'flex-col',
item: ''
},
horizontal: {
root: 'overflow-x-auto overflow-y-hidden',
viewport: 'flex-row',
item: ''
}
}
}
}
}
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import bitrix24UIPluginVite from '@bitrix24/b24ui-nuxt/vite'
export default defineConfig({
plugins: [
vue(),
bitrix24UIPluginVite({
b24ui: {
scrollArea: {
slots: {
root: 'relative',
viewport: 'relative flex',
item: ''
},
variants: {
orientation: {
vertical: {
root: 'overflow-y-auto overflow-x-hidden',
viewport: 'flex-col',
item: ''
},
horizontal: {
root: 'overflow-x-auto overflow-y-hidden',
viewport: 'flex-row',
item: ''
}
}
}
}
}
})
]
})