Veil UI
Components

Mobile Page Indicator

Dot indicators for swipeable mobile pages.

Installation

$ npx veil-ui@latest add mobile-page-indicator

Usage

import { MobilePageIndicator } from "@/components/ui/mobile-page-indicator";

<MobilePageIndicator count={4} index={index} onSelect={setIndex} />;

Examples

Basic

Slide 2
Page 2 of 4

Interactive

Slide 1
Page 1 of 3

API reference

The package exports mobile-page-indicator along with its composable parts. It forwards standard attributes to its root element; see the examples above for the component-specific props.

Accessibility

  • Touch targets are large enough to tap comfortably and keep visible focus rings for keyboard and switch users.
  • Gesture interactions (swipe, pull to refresh) have visible button alternatives so they are not the only way to act.
  • Sheets, drawers and dialogs follow the underlying accessible primitives for focus trapping and escape handling.

Vue and plain HTML

This component also ships for Vue (Reka UI) and plain HTML. Install it with npx veil-ui add mobile-page-indicator --framework vue or switch the framework in components.json.

<script setup lang="ts">
import { computed } from "vue";

import { cn } from "@/lib/utils";

import type { MobilePageIndicatorProps } from "./types";

defineOptions({ inheritAttrs: false });

const props = withDefaults(defineProps<MobilePageIndicatorProps>(), {
  label: "Pages",
});

const pages = computed(() =>
  Array.from({ length: props.count }, (_, page) => page),
);

function dotClasses(active: boolean) {
  return cn(
    "h-1.5 rounded-full transition-all",
    active ? "w-5 bg-primary" : "w-1.5 bg-muted-foreground/30",
  );
}
</script>

<template>
  <div
    data-slot="mobile-page-indicator"
    role="group"
    :aria-label="label"
    v-bind="$attrs"
    :class="cn('flex items-center justify-center gap-1.5', props.class)"
  >
    <template v-for="page in pages" :key="page">
      <span
        v-if="!props.onSelect"
        :aria-current="page === index ? 'true' : undefined"
        :class="dotClasses(page === index)"
      />
      <button
        v-else
        type="button"
        :aria-label="`Go to page ${page + 1}`"
        :aria-current="page === index ? 'true' : undefined"
        :class="
          cn(
            dotClasses(page === index),
            'outline-none focus-visible:ring-2 focus-visible:ring-ring',
          )
        "
        @click="props.onSelect(page)"
      >
        <span class="sr-only">Page {{ page + 1 }}</span>
      </button>
    </template>
    <span class="sr-only">Page {{ index + 1 }} of {{ count }}</span>
  </div>
</template>

On this page