Fragiola

API: components

Pagination

A navigation landmark of page buttons or links with Previous, Next, First, Last and ellipses, the current page marked aria-current, in each framework.

Moves between the pages of a paged list: a results table, a search, an archive. The APG has no pagination pattern and Base UI has no Pagination, so the behaviour is the APG-closest one: a navigation landmark you name, the current page marked aria-current="page" as the APG's breadcrumb marks its current link, and native buttons or links in the tab order (no arrow keys: it is no composite widget).

Results pager
Gallery

Behaviour

  • Page: from 1, controlled or not; a page outside [1, count] is clamped. count, or total and pageSize (ceil(total / pageSize)), never less than 1.
  • Range: the Root's children render it (React: a function; Vue: the default scoped slot; Angular: items()): every page while they fit in 2 × boundaryCount + 2 × siblingCount + 3 items, else the boundary pages, the window around the current page (kept whole near the ends), and an ellipsis on each side, never one that stands for a single page. With 10 pages and the defaults, page 5 gives 1 … 4 5 6 … 10.
  • Controls: Previous and First are disabled on the first page, Next and Last on the last; a press reports the new page with its reason (item-press, previous-press, next-press, first-press, last-press); the current page's Item reports nothing.
  • Links: render a link with nativeButton={false}: no type, aria-disabled instead of disabled, and its own navigation (the href, your router) goes on.
  • No text: name the Root (aria-label) and the arrows; an Item is named by its page number.

Anatomy

partelementdata-primitives-partrole
Rootnavpagination-rootthe landmark; holds the page and the range
Itembuttonpagination-itema page
Ellipsisspanpagination-ellipsisthe pages left out
Previousbuttonpagination-previousthe page before
Nextbuttonpagination-nextthe page after
Firstbuttonpagination-firstthe first page
Lastbuttonpagination-lastthe last page

Usage

import { Pagination } from "@fragiola/primitives-react/pagination";

<Pagination.Root aria-label="Results pages" total={95} pageSize={10} page={page} onPageChange={setPage}>
    {({ items }) => (
        <>
            <Pagination.Previous aria-label="Previous page">‹</Pagination.Previous>
            {items.map((item) =>
                item.type === "page" ? (
                    <Pagination.Item key={item.value} value={item.value}>
                        {item.value}
                    </Pagination.Item>
                ) : (
                    <Pagination.Ellipsis key={item.position}>…</Pagination.Ellipsis>
                ),
            )}
            <Pagination.Next aria-label="Next page">›</Pagination.Next>
        </>
    )}
</Pagination.Root>;

Props

Every part also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards. Vue binds them as props (v-model:page, :page-size, :native-button), and Angular as inputs ([(page)], [pageSize], [nativeButton]).

Root

proptypedefaultdescription
pagenumberthe current page, from 1 (controlled)
defaultPagenumber1the page at first
onPageChange(page, details) => voidevery page change, with its reason; Vue @page-change (and update:page), Angular (pageChangeDetails) (and (pageChange), the page alone)
countnumberthe number of pages
totalnumberthe number of rows, with pageSize, when count is not given
pageSizenumber10the rows per page
siblingCountnumber1the pages shown on each side of the current one
boundaryCountnumber1the pages always shown at each end
disabledbooleanfalseevery control is disabled

Item

proptypedefaultdescription
valuenumberrequiredits page
nativeButtonbooleantruefalse when it renders a link: no type, aria-disabled instead of disabled
onClick (react)MouseEventHandlera click, after the Item's own; not while disabled

Ellipsis

No props of its own; its children are its text.

Previous

proptypedefaultdescription
nativeButtonbooleantruefalse when it renders a link
onClick (react)MouseEventHandlera click, after the control's own; not while disabled

Next

proptypedefaultdescription
nativeButtonbooleantruefalse when it renders a link
onClick (react)MouseEventHandlera click, after the control's own; not while disabled

First

proptypedefaultdescription
nativeButtonbooleantruefalse when it renders a link
onClick (react)MouseEventHandlera click, after the control's own; not while disabled

Last

proptypedefaultdescription
nativeButtonbooleantruefalse when it renders a link
onClick (react)MouseEventHandlera click, after the control's own; not while disabled

State and part attributes

partattributes
Rootdata-disabled
Itemaria-current="page" and data-current on the current page; type="button"; data-disabled, with disabled (a button) or aria-disabled="true" (a link)
Previous, Firstdisabled on the first page: disabled or aria-disabled="true", data-disabled
Next, Lastdisabled on the last page, the same
Ellipsisnone

Keyboard

The browser's: Tab and Shift+Tab move through the enabled controls, Enter (and Space on a button) presses one. A disabled button is out of the tab order; a disabled link stays in it and its press does nothing.

Exports

entryexports
@fragiola/primitives-react/paginationPagination, ChangeDetails, ChangeReason, PaginationControlProps, PaginationControlState, PaginationEllipsisProps, PaginationFirstProps, PaginationItemProps, PaginationItemState, PaginationLastProps, PaginationNextProps, PaginationPreviousProps, PaginationRangeItem, PaginationRenderProps, PaginationRootProps, PaginationState, RenderProp
@fragiola/primitives-vue/paginationPagination, ChangeDetails, ChangeReason, PaginationControlProps, PaginationControlState, PaginationEllipsisState, PaginationItemProps, PaginationItemState, PaginationRangeItem, PaginationRootEmits, PaginationRootProps, PaginationRootSlots, PaginationSlotProps, PaginationState, RenderSlotProps
@fragiola/primitives-angular/paginationChangeDetails, ChangeReason, PaginationControlState, PaginationEllipsis, PaginationFirst, PaginationItem, PaginationItemState, PaginationLast, PaginationNext, PaginationPrevious, PaginationRangeItem, PaginationRoot, PaginationState, ValueChangeEvent