Vitral 0.2.18
Panel

ScrollPanel

A scroll container with the theme's own thin bars, over native scrolling — the bars every component that scrolls inside wears, and v-scrollbar puts on a box of your own.

Import

main.ts
import { ScrollPanel } from '@vitral/vue';

Vertical and horizontal

Paragraph 1. Vitral draws the scrollbars of this panel with the theme's tokens, while the browser keeps doing the scrolling, so the wheel, touch, and the arrow and page keys all work as they do anywhere else.

Paragraph 2. Vitral draws the scrollbars of this panel with the theme's tokens, while the browser keeps doing the scrolling, so the wheel, touch, and the arrow and page keys all work as they do anywhere else.

Paragraph 3. Vitral draws the scrollbars of this panel with the theme's tokens, while the browser keeps doing the scrolling, so the wheel, touch, and the arrow and page keys all work as they do anywhere else.

Paragraph 4. Vitral draws the scrollbars of this panel with the theme's tokens, while the browser keeps doing the scrolling, so the wheel, touch, and the arrow and page keys all work as they do anywhere else.

Paragraph 5. Vitral draws the scrollbars of this panel with the theme's tokens, while the browser keeps doing the scrolling, so the wheel, touch, and the arrow and page keys all work as they do anywhere else.

Paragraph 6. Vitral draws the scrollbars of this panel with the theme's tokens, while the browser keeps doing the scrolling, so the wheel, touch, and the arrow and page keys all work as they do anywhere else.

Paragraph 7. Vitral draws the scrollbars of this panel with the theme's tokens, while the browser keeps doing the scrolling, so the wheel, touch, and the arrow and page keys all work as they do anywhere else.

Paragraph 8. Vitral draws the scrollbars of this panel with the theme's tokens, while the browser keeps doing the scrolling, so the wheel, touch, and the arrow and page keys all work as they do anywhere else.

<script setup lang="ts">import { ScrollPanel } from '@vitral/vue'; const paragraphs = Array.from({ length: 8 }, (_, i) => `Paragraph ${i + 1}. Vitral draws the scrollbars of this panel with the theme's tokens, while the browser keeps doing the scrolling, so the wheel, touch, and the arrow and page keys all work as they do anywhere else.`);</script> <template>    <ScrollPanel aria-label="Notes" style="width: 100%; max-width: 28rem; height: 14rem; border: 1px solid var(--vt-content-border-color); border-radius: 8px">        <div style="padding: 1rem; width: 40rem">            <p v-for="p in paragraphs" :key="p" style="margin: 0 0 0.75rem">{{ p }}</p>        </div>    </ScrollPanel></template>

When the bars show

`scrollbar` is `'hover'` by default: the bars show while the pointer is over the panel, focus is inside it, or it scrolls. `'always'` keeps them on the screen, and `'native'` gives the browser's own back. `arrows` puts arrows at their ends, as a native bar has. The same prop is on every component that scrolls inside (Sidebar, Select, Dialog, Drawer, DataGrid and the rest), and the application's `scrollbar` option sets it for all of them at once. Only the thumb takes the pointer: a press on the track reaches the content under it.

  • Item 1
  • Item 2
  • Item 3
  • Item 4
  • Item 5
  • Item 6
  • Item 7
  • Item 8
  • Item 9
  • Item 10
  • Item 11
  • Item 12
  • Item 13
  • Item 14
  • Item 15
  • Item 16
  • Item 17
  • Item 18
  • Item 19
  • Item 20
  • Item 21
  • Item 22
  • Item 23
  • Item 24
<script setup lang="ts">import { ScrollPanel, SelectButton, ToggleSwitch } from '@vitral/vue';import { ref } from 'vue'; const mode = ref<'hover' | 'always' | 'native'>('always');const arrows = ref(false);const modes = ['hover', 'always', 'native'];const items = Array.from({ length: 24 }, (_, i) => `Item ${i + 1}`);</script> <template>    <div style="display: flex; flex-direction: column; gap: 1rem; align-items: flex-start">        <div style="display: flex; flex-wrap: wrap; align-items: center; gap: 1rem">            <SelectButton v-model="mode" :options="modes" :allow-empty="false" aria-label="Scrollbar" />            <label style="display: inline-flex; align-items: center; gap: 0.5rem"><ToggleSwitch v-model="arrows" /> Arrows</label>        </div>        <ScrollPanel :scrollbar="mode" :arrows="arrows" aria-label="Items" style="width: 16rem; max-height: 12rem; border: 1px solid var(--vt-content-border-color); border-radius: 8px">            <ul style="margin: 0; padding: 0.5rem 1rem; list-style: none">                <li v-for="item in items" :key="item" style="padding: 0.25rem 0">{{ item }}</li>            </ul>        </ScrollPanel>    </div></template>

Content that grows

The bars follow the content as well as the panel: a section opening with an animation, an image loading.

The bar is measured again when what is inside grows, not only when the panel does: open the section and its thumb shrinks while the section is still opening.

Section line 1. An image that finishes loading, or text that arrives, is followed in the same way.

Section line 2. An image that finishes loading, or text that arrives, is followed in the same way.

Section line 3. An image that finishes loading, or text that arrives, is followed in the same way.

Section line 4. An image that finishes loading, or text that arrives, is followed in the same way.

Section line 5. An image that finishes loading, or text that arrives, is followed in the same way.

Section line 6. An image that finishes loading, or text that arrives, is followed in the same way.

<script setup lang="ts">import { Button, ScrollPanel } from '@vitral/vue';import { ref } from 'vue'; const open = ref(false);</script> <template>    <div style="display: flex; flex-direction: column; gap: 1rem; align-items: flex-start">        <Button :label="open ? 'Close the section' : 'Open the section'" severity="secondary" @click="open = !open" />        <ScrollPanel scrollbar="always" aria-label="Report" style="width: 100%; max-width: 28rem; height: 12rem; border: 1px solid var(--vt-content-border-color); border-radius: 8px">            <div style="padding: 1rem">                <p style="margin: 0 0 0.75rem">The bar is measured again when what is inside grows, not only when the panel does: open the section and its thumb shrinks while the section is still opening.</p>                <div :style="{ display: 'grid', gridTemplateRows: open ? '1fr' : '0fr', transition: 'grid-template-rows 400ms ease' }">                    <div style="overflow: hidden">                        <p v-for="n in 6" :key="n" style="margin: 0 0 0.75rem">Section line {{ n }}. An image that finishes loading, or text that arrives, is followed in the same way.</p>                    </div>                </div>            </div>        </ScrollPanel>    </div></template>

Your own boxes

`v-scrollbar` puts the same bars on a box of your own that already scrolls, without wrapping it: it keeps its place in the layout and its native scrolling. `v-scrollbar.always`, `.hover` and `.native`, or a value, say when they show; with none, the application's `scrollbar` option decides. `.arrows` puts arrows at the ends, as a native bar has — a press scrolls a step, holding it keeps going — and the application's `scrollbarArrows` does the same for every bar.

Student 1

Student 2

Student 3

Student 4

Student 5

Student 6

Student 7

Student 8

Student 9

Student 10

Student 11

Student 12

Student 13

Student 14

Student 15

Student 16

Student 17

Student 18

Student 19

Student 20

Student 16.0
Student 26.7
Student 37.4
Student 48.1
Student 58.8
Student 69.5
Student 76.2
Student 86.9
Student 97.6
Student 108.3
Student 119.0
Student 129.7
Student 136.4
Student 147.1
Student 157.8
Student 168.5
Student 179.2
Student 189.9
Student 196.6
Student 207.3

Student 1: grade 6.0, entered on the term's sheet

Student 2: grade 6.7, entered on the term's sheet

Student 3: grade 7.4, entered on the term's sheet

Student 4: grade 8.1, entered on the term's sheet

Student 5: grade 8.8, entered on the term's sheet

Student 6: grade 9.5, entered on the term's sheet

Student 7: grade 6.2, entered on the term's sheet

Student 8: grade 6.9, entered on the term's sheet

Student 9: grade 7.6, entered on the term's sheet

Student 10: grade 8.3, entered on the term's sheet

Student 11: grade 9.0, entered on the term's sheet

Student 12: grade 9.7, entered on the term's sheet

Student 13: grade 6.4, entered on the term's sheet

Student 14: grade 7.1, entered on the term's sheet

Student 15: grade 7.8, entered on the term's sheet

Student 16: grade 8.5, entered on the term's sheet

Student 17: grade 9.2, entered on the term's sheet

Student 18: grade 9.9, entered on the term's sheet

Student 19: grade 6.6, entered on the term's sheet

Student 20: grade 7.3, entered on the term's sheet

<script setup lang="ts">import { Scrollbar as vScrollbar } from '@vitral/vue'; const rows = Array.from({ length: 20 }, (_, i) => ({ id: i + 1, name: `Student ${i + 1}`, grade: (6 + ((i * 7) % 40) / 10).toFixed(1) }));</script> <template>    <div style="display: flex; flex-wrap: wrap; gap: 1rem">        <div v-scrollbar aria-label="Students" role="region" tabindex="0" style="width: 16rem; height: 12rem; overflow: auto; border: 1px solid var(--vt-content-border-color); border-radius: 8px">            <p v-for="row in rows" :key="row.id" style="margin: 0; padding: 0.375rem 1rem">{{ row.name }}</p>        </div>        <div v-scrollbar.always aria-label="Grades" role="region" tabindex="0" style="width: 16rem; height: 12rem; overflow: auto; border: 1px solid var(--vt-content-border-color); border-radius: 8px">            <table style="width: 100%; border-collapse: collapse">                <tbody>                    <tr v-for="row in rows" :key="row.id">                        <td style="padding: 0.375rem 1rem">{{ row.name }}</td>                        <td style="padding: 0.375rem 1rem; text-align: right">{{ row.grade }}</td>                    </tr>                </tbody>            </table>        </div>        <div v-scrollbar.always.arrows aria-label="Term notes" role="region" tabindex="0" style="width: 16rem; height: 12rem; overflow: auto; border: 1px solid var(--vt-content-border-color); border-radius: 8px">            <div style="width: 26rem; padding: 0.5rem 1rem">                <p v-for="row in rows" :key="row.id" style="margin: 0; padding: 0.25rem 0">{{ row.name }}: grade {{ row.grade }}, entered on the term's sheet</p>            </div>        </div>    </div></template>

API

Read from packages/vue/src/components/ScrollPanel/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
arrows New in 0.2.16booleanArrows at the ends of the bars, as a native bar has: a press scrolls a step and holding it keeps scrolling. The application's `scrollbarArrows` by default, which is off.
scrollbar ScrollbarModeThe bars of the boxes this component scrolls inside — `'hover'`, `'always'` or `'native'`. The application's `scrollbar` option by default, which is `'hover'`.

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Slots

NameSlot propsDescription
default ——