Navigation · Pagination

Pagination

The Pager helps users navigate between multiple pages

Demos

How to import

import { Pagination } from '@fibrous/semi-ui-react';

Basic Usage

Set the total number via total, set capacity per page via pageSize.

Code
import { Pagination } from '@fibrous/semi-ui-react';

export default function PaginationDemo() {
    return (
        <div>
            <Pagination total={30} style={{ marginBottom: 12 }} />
            <Pagination total={80} style={{ marginBottom: 12 }} />
            <Pagination total={200} style={{ marginBottom: 12 }} />
            <Pagination total={80} pageSize={30} style={{ marginBottom: 12 }} />
        </div>
    );
}

disabled

Disabled via the disabled setting

Code
import { Pagination } from '@fibrous/semi-ui-react';

export default function PaginationDemo() {
    return <Pagination total={30} disabled style={{ marginBottom: 12 }} />;
}

Show total page number

Use the showTotal property to control whether the total number of pages is shown.

  • 总页数:8
  • 总页数:20
Code
import { Pagination } from '@fibrous/semi-ui-react';

export default function PaginationDemo() {
    return (
        <div>
            <Pagination total={80} showTotal style={{ marginBottom: 12 }} />
            <Pagination total={200} showTotal style={{ marginBottom: 12 }} />
        </div>
    );
}

Specify current page number

You can specify the currently active page number via defaultCurrentPage.

  • 总页数:8
Code
import { Pagination } from '@fibrous/semi-ui-react';

export default function PaginationDemo() {
    return (
        <div>
            <Pagination total={80} showTotal defaultCurrentPage={3} />
        </div>
    );
}

Capacity switching per page

By setting showSizeChanger for true, allowing quick switching of capacity per page via the Select component

Code
import { Pagination } from '@fibrous/semi-ui-react';

export default function PaginationDemo() {
    return (
        <div>
            <Pagination total={80} showSizeChanger style={{ marginBottom: 12 }} />
            <Pagination total={300} showSizeChanger />
        </div>
    );
}

Jump to a page quickly

By setting showQuickJumper to true, you can enter the page number through the Input control to quickly jump
When Input loses focus, if there is a valid number in Input, it will jump directly. You can also enter the page number you want to jump to when the Input is focused, and then hit enter to jump directly
If you enter a page number greater than the total page number of the pager, we will automatically jump to the last page for you

  • 跳至
    页
  • 跳至
    页
Code
import { Pagination } from '@fibrous/semi-ui-react';

export default function PaginationDemo() {
    return (
        <div>
            <Pagination total={80} showQuickJumper style={{ marginBottom: 12 }} />
            <Pagination total={300} showQuickJumper />
        </div>
    );
}

Page number controlled

After the currentPage is passed in, the pager is a controlled component and is generally used in conjunction with onPageChange. The current active page number depends entirely on the value of the currentPage passed in.

Code
import { useState } from 'react';
import { Pagination } from '@fibrous/semi-ui-react';

export default function PaginationDemo() {
    const [page, setPage] = useState(3);
    function onPageChange(currentPage: number) {
        setPage(currentPage);
    }
    return <Pagination total={200} currentPage={page} onPageChange={onPageChange} />;
}

Preset capacity per page

Specify an optional value for switching the capacity per page by using the pageSizeOpts array

Code
import { Pagination } from '@fibrous/semi-ui-react';

export default function PaginationDemo() {
    return (
        <div>
            <Pagination total={300} showSizeChanger style={{ marginBottom: 12 }} pageSizeOpts={[50, 80, 90, 200]} />
            <Pagination total={300} showSizeChanger pageSizeOpts={[10, 20, 50, 200]} />
        </div>
    );
}

Mini version

Show mini pagination via size properties.

  • 1/9
Code
import { Pagination } from '@fibrous/semi-ui-react';

export default function PaginationDemo() {
    return <Pagination total={90} size="small" />;
}

Turn on hoverShowPageSelect to open the page list by hovering the page text and switch pages quickly

Code
import { Pagination } from '@fibrous/semi-ui-react';

export default function PaginationDemo() {
    return <Pagination total={90} size="small" hoverShowPageSelect />;
}

API reference

Props

PropertyDescriptionTypeDefault
classNameClass name of the root ul element.string""
currentPageCurrent page. Once set the pagination is controlled and the page is entirely determined by this prop; when undefined the component manages the page itself.number-
defaultCurrentPageInitial page when not controlled.number1
disabledWhether disabled. When disabled, the navigation buttons, the page numbers, the size changer and the quick jumper are all unavailable.booleanfalse
hideOnSinglePageWhether to hide the pagination when there are fewer than 2 pages; has no effect while the size changer is shown.booleanfalse
hoverShowPageSelectOnly when size is small: the page list opens when the page text is hovered or focused.boolean-
nextTextReplaces the content of the next page button, named the same way as prevText.React.ReactNode-
onChangeCalled when the page or the page size changes, with the page and the page size.Type(currentPage: number, pageSize: number) => void-
onPageChangeCalled when the page changes, with the new page.Type(currentPage: number) => void-
onPageSizeChangeCalled when the page size changes, with the new page size.Type(newPageSize: number) => void-
pageSizeNumber of items per page; falls back to the first item of pageSizeOpts. Not strictly controlled: the choice made in the size changer is kept inside, and only a change of this prop to a value other than the current one overrides it and goes back to page 1 (to currentPage when controlled). Writing it back from onChange does not reset the page.numbernull
pageSizeOptsOptions of the size changer; the current page size is inserted in order when it is not among them.TypeArray<number>[10, 20, 40, 100]
popoverPositionPosition of the omitted pages popover and the size changer dropdown. When omitted the size changer dropdown uses bottomLeft (bottomRight in RTL) and the omitted pages popover uses the Popover default bottom; not used when size is small.PopoverPosition-
preventPageChangeOnPageSizeChangeKeeps the current page when the page size changes without calling onPageChange; the consumer picks the new page in onPageSizeChange.booleanfalse
prevTextReplaces the content of the previous page button. A plain text names the button, and any other content (an icon, an element) keeps the locale name; empty content keeps the default icon and the locale name.React.ReactNode-
refRef of the root ul element, in both sizes.TypeReact.Ref<HTMLUListElement>-
showQuickJumperWhether to show the quick jump input; disabled when there are fewer than 2 pages.booleanfalse
showSizeChangerWhether to show the size changer; has no effect when size is small. When it is shown, hideOnSinglePage no longer takes effect.booleanfalse
showTotalWhether to show the total number of pages; not shown when size is small.booleanfalse
sizeSize: default or small.'small' | 'default'"default"
styleInline style of the root ul element.React.CSSProperties-
totalTotal number of items. When it changes, an uncontrolled pagination goes back to page 1; when controlled, the page follows currentPage.number1

Other native attributes (such as id, aria-*, data-* and onClick) fall through to the root ul, in both the default and the small size; onChange, onPageChange and onPageSizeChange are component callbacks and do not land on the root element.

Accessibility

Pagination follows the common practice of the WAI-ARIA navigation example.

ARIA

  • The root is a ul, and every part (total, previous, pages, next, page size, quick jumper) is an li in it
  • Previous, next, the pages and "…" are native buttons. A page is named "Page N", "…" is named "More", and previous and next are named by the locale by default; with prevText or nextText (slots of the same name in Vue) holding plain text they are named by that text, while icons, elements and other content keep the locale name
  • The button of the current page has aria-current="page"; disabled buttons use the native disabled
  • The quick jumper input is named "Jump to" and is disabled when there are fewer than 2 pages
  • The component itself is not a navigation landmark. When the pagination is a main way to navigate the page, wrap it in a <nav aria-label="..."> and tell multiple paginations on the page apart by their names

Keyboard and Focus

  • Previous, next, the pages and "…" can be focused with Tab, and Enter or Space turns the page;
  • Keyboard focus on "…", or on the page text in small mode with hoverShowPageSelect, opens the list of the omitted pages:
    • Down Arrow focuses the first page in the list, Up Arrow focuses the last one;
    • Tab and Shift + Tab move in the list, Enter or Space jumps to the page;
    • Esc closes the list and returns focus to the trigger button.

Design Tokens

These are the component's internal Sass variables and cannot be overridden. To customize styles, override the --semi-* CSS variables (see the Design Token page) or write unlayered CSS rules.
Sass variableValueUsage
$transition_duration-pagination_item-bgvar(--semi-transition_duration-none)翻页器页码-背景色-动画持续时间
$transition_function-pagination_item-bgvar(--semi-transition_function-easeIn)翻页器页码-背景色-过渡曲线
$transition_delay-pagination_item-bgvar(--semi-transition_delay-none)翻页器页码-背景色-延迟时间
$transition_duration-pagination_item-textvar(--semi-transition_duration-none)翻页器页码文本-背景色-动画持续时间
$transition_function-pagination_item-textvar(--semi-transition_function-easeIn)翻页器页码文本-背景色-过渡曲线
$transition_delay-pagination_item-textvar(--semi-transition_delay-none)翻页器页码文本-背景色-延迟时间
$transform_scale-pagination_itemvar(--semi-transform_scale-none)翻页器item-放大
$color-pagination-text-defaultvar(--semi-color-text-2)翻页器总页数文本颜色
$color-pagination_item-text-defaultvar(--semi-color-text-0)翻页器 页码 文本颜色
$color-pagination_item-icon-defaultvar(--semi-color-tertiary)翻页器 页码 图标颜色
$color-pagination_item-text-hovervar(--semi-color-text-0)翻页器 页码 悬浮态文本颜色
$color-pagination_item-bg-hovervar(--semi-color-fill-0)翻页器 页码 悬浮态背景颜色
$color-pagination_item-text-activevar(--semi-color-text-0)翻页器 页码 按下态文字颜色
$color-pagination_item-bg-activevar(--semi-color-fill-1)翻页器 页码 按下态背景颜色
$color-pagination_item-text-disabledvar(--semi-color-disabled-text)翻页器 页码 禁用态文字颜色
$color-pagination_item-icon-disabledvar(--semi-color-disabled-text)翻页器 页码 禁用态图标颜色
$color-pagination_item-bg-disabledtransparent翻页器 页码 禁用态背景颜色
$color-pagination_item-bg-selected-disabledvar(--semi-color-disabled-fill)翻页器 页码 选中禁用态背景颜色
$color-pagination_item-text-selectedvar(--semi-color-primary)翻页器 页码 选中态文字颜色
$color-pagination_item-bg-selectedvar(--semi-color-primary-light-default)翻页器 页码 选中态背景颜色
$color-pagination_quickjump_text-disabledvar(--semi-color-disabled-text)翻页器 快速跳转禁用态文字颜色
$color-pagination_item-border-defaulttransparent翻页器 页码 默认边框颜色
$color-pagination_item-border-hovertransparent翻页器 页码 悬浮边框颜色
$color-pagination_item-border-activetransparent翻页器 页码 激活边框颜色
$color-pagination_item-border-selectedtransparent翻页器 页码 选中边框颜色
$color-pagination_item-border-disabledtransparent翻页器 页码 禁用边框颜色
$height-pagination_item32px翻页器 页码高度
$width-pagination_item-minWidth32px翻页器 页码最小宽度
$width-pagination_item_small-minWidth44px迷你翻页器 页码最小宽度
$width-pagination_quickjump_input_width50px快速跳转输入框宽度
$width-pagination_item_border0px翻页器 页码 默认边框宽度
$spacing-pagination-padding0翻页器内边距
$spacing-pagination_small-paddingY0迷你翻页器垂直内边距
$spacing-pagination_small-paddingX0迷你翻页器水平内边距
$spacing-pagination_item-marginLeft$spacing-extra-tight翻页器页码左侧外边距
$spacing-pagination_item-marginRight$spacing-extra-tight翻页器页码右侧外边距
$spacing-pagination_item_small-margin0迷你翻页器页码外边距
$spacing-pagination_reset_list-paddingTop$spacing-extra-tight
$spacing-pagination_reset_list-paddingBottom$spacing-extra-tight
$spacing-pagination_quickjump_marginLeft24px快速跳转左侧外边距
$spacing-pagination_quickjump_input_marginLeft4px快速跳转输入框左侧外边距
$spacing-pagination_quickjump_input_marginRight4px快速跳转输入框右侧外边距
$radius-pagination_itemvar(--semi-border-radius-small)翻页器页码圆角大小
$font-pagination_small-fontWeight$font-weight-regular迷你翻页器字重
$font-pagination_item-fontWeight$font-weight-regular翻页器页码字重
$font-pagination_item_active-fontWeight$font-weight-bold翻页器页码选中态字重