Page Indicator

new

Dots, a pill or line segments that mark the current page or slide, built on Reka UI.

Demo
Mountains
Forest
Lake
Desert
Coast

Open Props in the corner of the example to try variant, color and size. dot marks the current page by colour, pill also stretches it, and line shares the root's length between segments.

size goes from xs (4px dots) to xl (12px) and scales the gap and the pill with it.

color sets the tone of the fill, and the track is a fainter shade of it. Over a picture, set the tone itself with class="[--tone:white]".

Installation

Usage

<script setup lang="ts">
import { ref } from 'vue'

import { PageIndicator, PageIndicatorItem } from '@/components/ui/page-indicator'

const page = ref(1)
</script>

<template>
  <PageIndicator v-slot="{ pages }" v-model:page="page" :count="5">
    <PageIndicatorItem v-for="value in pages" :key="value" :value="value" />
  </PageIndicator>
</template>

PageIndicator shows where the user is among count pages: under a carousel, over a story, beside a vertical slider. It holds the page, counted from 1, and hands pages to its slot; each PageIndicatorItem stands for one value. An item's state lands as data-state: active for the current page, completed for the pages before it, inactive for the rest.

The items are buttons with roving focus: Tab reaches the current page only, the arrow keys, Home and End move between pages, and a click, Enter or Space selects one. Each button reaches half the gap past its dot, so the row has no dead space between pages, and a hover or a press lights that whole area up, as on a Checkbox; touchTarget grows it to a finger's 48px. The root is a role="group" named "Pages" and each item "Page n"; put your own aria-label on the root and on the items to name the slides instead.

PageIndicator does not page anything by itself. Bind v-model:page to whatever shows the pages, or listen to update:page and move it there, as the demo does with a scroll-snap gallery. The demo sets the clicked page at once and ignores the slides its smooth scroll passes on the way; reading the page from every scroll event would walk the pill through each of them.

Examples

Vertical

orientation="vertical" stacks the pages, the pill stretches downwards and the up and down arrows move focus. A vertical line fills the root's height.

Vertical page indicator

Stories

cumulative fills the pages before the current one, and progress fills the current one from 0 to 1, so story bars need only a timer: here a requestAnimationFrame loop that the button starts and pauses. readonly turns the items into plain shapes and the root into an image labelled "Page n of m", renamed here to "Story n of m".

Stories
Sunrise

Touch target

Smaller than a finger? Add touch-target: expand when it stands alone, wrapper when it sits close to others. How it works.

With wrapper, the dots spread apart.

Touch target

API Reference

Every part accepts class, merged over its base classes.

Changelog

  1. registry 0.22.1

    20b5be9 — PageIndicator: each page's pressable area now reaches half the gap past its dot, so the row has no dead space between pages, and a hover or a press lights that area up as a halo, as on Checkbox; the dot itself no longer darkens on hover. touchTarget still grows the area to 48px.

  2. registry 0.22.0

    d5fd78c — A width class on a line PageIndicator (w-40, or h-* when vertical) now sets its length instead of losing to the data-[orientation] rule that stretched it across its parent.

  3. registry 0.21.0

    2fac232 — PageIndicator: the dots after a moving pill no longer jump a pixel while it eases. tailwind.css registers --page-indicator-length with @property, the items transition it instead of width, and each item takes it rounded to whole pixels, up for the current page and down for the rest, so the two lengths that trade places always add up to the same width.

  4. core 0.15.1

    2fac232 — PageIndicator: the dots after a moving pill no longer jump a pixel while it eases. tailwind.css registers --page-indicator-length with @property, the items transition it instead of width, and each item takes it rounded to whole pixels, up for the current page and down for the rest, so the two lengths that trade places always add up to the same width.

  5. registry 0.9.0

    3fcff02 — New PageIndicator: marks the current page among count as dots, a stretched pill or line segments, with a PageIndicatorItem per page. v-model:page counts from 1; five sizes, any tone, both orientations; cumulative and progress fill story bars and autoplay; readonly turns it into a labelled picture; touchTarget grows the pressable areas. The items are buttons with roving focus.