Pagination
Controlled page navigation for bounded or large result sets.
Available in alpha.5
Available in Mavis alpha.5.
| Prop | Type | Default | Purpose |
|---|---|---|---|
modelValue | number | 1 | One-based requested page. |
total | number | required | Nonnegative safe-integer result count. |
pageSize | number | 20 | Positive safe-integer page size. |
siblingCount | 0 | 1 | 2 | 1 | Neighbor pages around the current page. |
loading / disabled | boolean | false | Prevents page requests. |
label | string | Result pages | Navigation name. |
update:modelValue(page) requests a different valid page. Previous/next disable at the boundaries. An empty collection keeps the host's page 1 and renders no fictitious numbered page. The rendered page set is bounded independently of the total, with inert ellipses. Web marks the selected page with aria-current="page".
When filtering or deleting makes the parent's page invalid, the control shows invalidPageLabel and lets the host decide how to recover; it never mutates selection during render. Use pagination(total, pageSize, page) or pageCount(total, pageSize) for the same neutral calculations.
Localize previousLabel, nextLabel, pageLabel, currentLabel, emptyLabel and invalidPageLabel. The host owns loading, result announcements, cancellation, error/retry and router/query synchronization. Keep results and controls mounted during requests to retain focus. The recipe demonstrates filter reset to page 1 and generation checks against stale responses using a local dataset. Cursor pagination is a different service contract and is not inferred from a total.
A small bar under the current page marks it. When the parent accepts a new page, the bar travels from the old page to the new one, across rows when the control wraps. On Web, page buttons can slide when the visible window changes while focus is outside the pager. Moving focus into the pager settles them immediately. On NativeScript the page buttons take their new positions immediately, including when the operating system handles keyboard or accessibility focus. On both platforms the decorative bar can travel to the new current page. The bar is decorative and hidden from assistive technology; the current page is still announced through aria-current on Web and currentLabel on native. Reduced motion places it at once.
statusText supplies a host-owned, polite result announcement (for example, the loaded page and result count). Action labels remain available during loading. If the platform moves focus away when a page action becomes disabled, the pager can restore focus to the current page after loading. Moving focus to another control during the request takes precedence.
Chromium on macOS. Tab moves focus to pages 2 and 5. Enter selects each page. When the page window shifts, page 5 retains the focus ring and the bar settles beneath it.
iPhone simulator. The native page action switches from page 2 to page 5. The button takes its new position without a sliding animation. UIKit declined keyboard focus in this simulator configuration.
Android emulator. Page 5 has keyboard focus when activated and again when the accepted request completes. The row updates immediately while the selection marker moves.
<script setup lang="ts">
import { useCatalogLocale } from '../locale'
import { computed, onScopeDispose, ref, watch } from 'vue'
const { t, locale } = useCatalogLocale(() => props.lang)
const props = withDefaults(defineProps<{ lang?: 'en' | 'pt' }>(), { lang: undefined })
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const all = [
'Recife',
'Salvador',
'Santos',
'São Paulo',
'Natal',
'Fortaleza',
'Belém',
'Manaus',
'Curitiba',
'Maceió',
'João Pessoa',
'Florianópolis',
'Rio de Janeiro',
]
const query = ref('')
const page = ref(1)
const total = ref(all.length)
const rows = ref(all.slice(0, 3))
const loading = ref(false)
let revision = 0
let timer: ReturnType<typeof setTimeout> | undefined
function load(next: number) {
clearTimeout(timer)
const request = ++revision
const filter = query.value.toLocaleLowerCase('pt-BR')
loading.value = true
// Replace this local dataset with the host's request, preserving the generation check.
timer = setTimeout(() => {
if (request !== revision) return
const result = all.filter((item) => item.toLocaleLowerCase('pt-BR').includes(filter))
const current = Math.max(1, Math.min(next, Math.ceil(result.length / 3)))
total.value = result.length
page.value = current
rows.value = result.slice((current - 1) * 3, current * 3)
loading.value = false
}, 250)
}
watch(query, () => load(1))
onScopeDispose(() => {
revision++
clearTimeout(timer)
})
</script>
<template>
<m-column gap="lg">
<m-input v-model="query" :label="t(pt ? 'Filtrar destinos' : 'Filter destinations')" />
<m-column gap="sm" id="pagination-results">
<m-card v-for="(city, index) in rows" :key="city" padding="md" gap="xs">
<m-text variant="overline" tone="primary"
>{{ t(String((page - 1) * 3 + index + 1).padStart(2, '0')) }}{{ t(' / BRASIL') }}</m-text
>
<m-text variant="heading">{{ t(city) }}</m-text>
</m-card>
</m-column>
<m-pagination
:modelValue="page"
:total="total"
:pageSize="3"
:loading="loading"
:statusText="
loading
? pt
? 'Buscando destinos…'
: 'Loading destinations…'
: `${pt ? 'Página' : 'Page'} ${page} · ${rows.length} ${pt ? 'nesta página' : 'on this page'} · ${total} ${pt ? 'destinos' : 'destinations'}`
"
:label="t(pt ? 'Páginas de destinos' : 'Destination pages')"
:previousLabel="t(pt ? 'Anterior' : 'Previous')"
:nextLabel="t(pt ? 'Próxima' : 'Next')"
:pageLabel="pt ? 'Página' : 'Page'"
:currentLabel="pt ? 'Atual' : 'Current'"
:emptyLabel="t(pt ? 'Nenhum destino encontrado' : 'No destinations found')"
@update:modelValue="load"
/>
</m-column>
</template>Desktop
On the desktop the pages and the previous and next actions are native buttons, statusText is announced, and a page that had the keyboard and then left gives it to the current page once the request is over. See Desktop components.