vael-ui v0.5.7

Layout & structure

Layout

ScrollArea

A scroll box with slim, themed scrollbars and faded edges, in one or both directions. Use it for panels and lists that scroll inside the page.

Install

import { ScrollArea } from 'vael-ui'

Playground

  • 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

Placement, behaviour and animation

Usage
<script setup lang="ts">
import { ScrollArea } from 'vael-ui'
</script>

<template>
  <ScrollArea>
    <ul>
      <li v-for="n in 20" :key="n">Item {{ n }}</li>
    </ul>
  </ScrollArea>
</template>

Props

NameTypeDefaultDescription
orientation'horizontal' | 'vertical' | 'both''vertical'Which axis (or axes) the viewport scrolls along.
scrollFadebooleantrueMasks the scrolling edge(s) as content scrolls under them.
autoHidebooleanfalseHides the scrollbar thumb until you hover, focus or scroll the viewport.
motionScrollAreaMotionHow it moves: its appearance ({ initial: { root: { opacity: 0, y: 4 } } }). false turns its own animation off.
uiPartial<Record<'root' | 'viewport', UiPartValue>>Class and style overrides for each part.

Events

NameTypeDescription
scroll(event: Event)Fires when the viewport scrolls.

Slots

NameTypeDescription
defaultanyScrollable content.

Exposed

NameTypeDescription
elHTMLElement | nullRoot element.
viewportElHTMLElement | nullScrolling viewport element.
scrollTopnumberVertical scroll offset in pixels. Writable: assigning it scrolls the viewport.
scrollLeftnumberHorizontal scroll offset in pixels. Writable: assigning it scrolls the viewport.
atTopbooleanWhether the viewport is scrolled to the top.
atBottombooleanWhether the viewport is scrolled to the bottom.
atStartbooleanWhether the viewport is scrolled to the left edge.
atEndbooleanWhether the viewport is scrolled to the right edge.
isScrollingReadonly<{ value: boolean; }>true while a scroll is in progress, including native momentum or rubber-band settling.
directionsReadonly<Edges>Direction of the current scroll, as top, bottom, left and right flags.
scrollTo(options: ScrollToOptions) => voidScrolls the viewport with native ScrollToOptions.
scrollToTop(options?: Omit<ScrollToOptions, "top"> | undefined) => voidSmooth-scrolls to the top.
scrollToBottom(options?: Omit<ScrollToOptions, "top"> | undefined) => voidSmooth-scrolls to the bottom.
scrollToStart(options?: Omit<ScrollToOptions, "left"> | undefined) => voidSmooth-scrolls to the left edge.
scrollToEnd(options?: Omit<ScrollToOptions, "left"> | undefined) => voidSmooth-scrolls to the right edge.
partsRecord<string, HTMLElement | HTMLElement[] | null>Its elements by part name, for your own animation; a repeated part is an array.

Motion New

ScrollArea: its appearance.

<ScrollArea
  :motion="{ initial: { root: { opacity: 0, y: 4 } } }"
/>
NameTypeDescription
initialexitrootSets where each part comes in from and leaves to: any CSS property, plus x, y and blur. A plain number is px, or degrees for rotate.
enterleave(parts, context) => animationAnimates the parts with GSAP, motion or element.animate(). Return the animation and the component waits for it, and stops it if interrupted.
springdurationeasing{ damping, response } | number | stringTimes all of it: a spring, or a duration in ms with an easing. Never both.
falsebooleanTurns its motion off, for an animation of your own on its exposed elements.

Accessibility

It has no keyboard interaction of its own.

  • The viewport is a native scroller with a native scrollbar, so the browser handles scrolling keys once focus is inside it.
  • While the content overflows and holds nothing focusable, the viewport gets tabindex="0", so you can reach it with Tab.
  • aria-label and aria-labelledby go on the viewport, which then becomes a role="region". Other attributes go on the root.