Page Indicator
newDots, a pill or line segments that mark the current page or slide, built on Reka UI.
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.
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".
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.
API Reference
Every part accepts class, merged over its base classes.
PageIndicator
| Prop | Default | Type and description |
|---|---|---|
| count* | — | numberHow many pages there are. The default slot receives them as |
| page | — | numberThe current page, counted from 1, bound with |
| defaultPage | 1 | numberThe page shown at first when |
| variant | "dot" | PageIndicatorVariant
|
| size | "md" | PageIndicatorSizeDot and line thickness from 4px for |
| color | "primary" | PageIndicatorColor | (string & {})The tone of the fill; the track is a fainter shade of it. Any name declared on |
| orientation | "horizontal" | PageIndicatorOrientation
|
| cumulative | — | booleanFills the pages before the current one as well, as story bars and step dots do. |
| progress | — | numberHow much of the current page is filled, from 0 to 1, for autoplay. Without it the current page is full. |
| readonly | — | booleanShows the page without buttons or focus: the root becomes an image labelled "Page n of m". |
| touchTarget | "none" | PageIndicatorTouchTargetGrows each page's pressable area to at least 48px without changing how it looks. |
| dir | — | DirectionReading direction. Inherits from a surrounding |
| Event | Payload and description |
|---|---|
| update:page | [value: number]Fires with the page a click, Enter or Space selects. |
| Slot | Scope and description |
|---|---|
| default | { pages: number[]; page: number; }The items. Receives |
PageIndicatorItem
| Prop | Default | Type and description |
|---|---|---|
| value* | — | numberThe page this item stands for, counted from 1. |
Props
- count*
numberHow many pages there are. The default slot receives them aspages.- page
numberThe current page, counted from 1, bound withv-model:page.- defaultPage
1 numberThe page shown at first whenv-model:pageis not used.- variant
"dot" PageIndicatorVariantdotmarks the current page by colour,pillalso stretches it,lineshares the length between segments.- size
"md" PageIndicatorSizeDot and line thickness from 4px forxsto 12px forxl, with the gap and the pill length to match.- color
"primary" PageIndicatorColor | (string & {})The tone of the fill; the track is a fainter shade of it. Any name declared on[data-slot][data-color]works too.- orientation
"horizontal" PageIndicatorOrientationhorizontallays the pages out in a row,verticalin a column. Arrow keys follow the orientation.- cumulative
booleanFills the pages before the current one as well, as story bars and step dots do.- progress
numberHow much of the current page is filled, from 0 to 1, for autoplay. Without it the current page is full.- readonly
booleanShows the page without buttons or focus: the root becomes an image labelled "Page n of m".- touchTarget
"none" PageIndicatorTouchTargetGrows each page's pressable area to at least 48px without changing how it looks.wrapperalso reserves that space in layout;expandmay overlap neighbours.- dir
DirectionReading direction. Inherits from a surroundingConfigProviderwhen not set. Otherwiseltr.
Emits
- update:page
[value: number]Fires with the page a click, Enter or Space selects.
Slots
- default
{ pages: number[]; page: number; }The items. Receivespages, the numbers from 1 tocount, and the currentpage.
Props
- value*
numberThe page this item stands for, counted from 1.