Navigation · Pagination

Pagination

The Pager helps users navigate between multiple pages

Demos

How to import

<script lang="ts">
    import { Pagination } from '@fibrae/semi-ui-svelte';
</script>

Basic Usage

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

Code
<script lang="ts">
    import { Pagination } from '@fibrae/semi-ui-svelte';
</script>

<div>
    <Pagination style="margin-bottom: 12px" total={30} />
    <Pagination style="margin-bottom: 12px" total={80} />
    <Pagination style="margin-bottom: 12px" total={200} />
    <Pagination pageSize={30} style="margin-bottom: 12px" total={80} />
</div>

disabled

Disabled via the disabled setting

Code
<script lang="ts">
    import { Pagination } from '@fibrae/semi-ui-svelte';
</script>

<Pagination disabled style="margin-bottom: 12px" total={30} />

Show total page number

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

  • 总页数:8
  • 总页数:20
Code
<script lang="ts">
    import { Pagination } from '@fibrae/semi-ui-svelte';
</script>

<div>
    <Pagination showTotal style="margin-bottom: 12px" total={80} />
    <Pagination showTotal style="margin-bottom: 12px" total={200} />
</div>

Specify current page number

There is no defaultCurrentPage: pass currentPage={3} as the initial page. After a click the page becomes a local value of the component.

  • 总页数:8
Code
<script lang="ts">
    import { Pagination } from '@fibrae/semi-ui-svelte';
</script>

<div>
    <Pagination currentPage={3} showTotal total={80} />
</div>

Capacity switching per page

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

Code
<script lang="ts">
    import { Pagination } from '@fibrae/semi-ui-svelte';
</script>

<div>
    <Pagination showSizeChanger style="margin-bottom: 12px" total={80} />
    <Pagination showSizeChanger total={300} />
</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
<script lang="ts">
    import { Pagination } from '@fibrae/semi-ui-svelte';
</script>

<div>
    <Pagination showQuickJumper style="margin-bottom: 12px" total={80} />
    <Pagination showQuickJumper total={300} />
</div>

Page number controlled

Bind the page with bind:currentPage; bind:currentPage={get, set} makes the pagination fully controlled, and the setter decides whether to accept a new page. When currentPage is omitted the component manages the page itself.

Code
<script lang="ts">
    import { Pagination } from '@fibrae/semi-ui-svelte';

    let page = $state(3);
</script>

<Pagination bind:currentPage={page} total={200} />

Preset capacity per page

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

Code
<script lang="ts">
    import { Pagination } from '@fibrae/semi-ui-svelte';
</script>

<div>
    <Pagination pageSizeOpts={[50, 80, 90, 200]} showSizeChanger style="margin-bottom: 12px" total={300} />
    <Pagination pageSizeOpts={[10, 20, 50, 200]} showSizeChanger total={300} />
</div>

Mini version

Show mini pagination via size properties.

  • 1/9
Code
<script lang="ts">
    import { Pagination } from '@fibrae/semi-ui-svelte';
</script>

<Pagination size="small" total={90} />

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

Code
<script lang="ts">
    import { Pagination } from '@fibrae/semi-ui-svelte';
</script>

<Pagination hoverShowPageSelect size="small" total={90} />

API reference

Props

PropertyDescriptionTypeDefault
currentPageCurrent page, bound with bind:currentPage. When omitted the component manages the page itself; bind:currentPage={get, set} makes it fully controlled.number-
disabledWhether disabled.booleanfalse
hideOnSinglePageWhether to hide the pagination when there are fewer than 2 pages; has no effect while the size changer is shown.booleanfalse
hoverShowPageSelectOnly for size small: the page list opens when the page text is hovered or focused.boolean-
nextTextString or snippet that replaces the next page icon, named the same way as prevText.string | Snippet-
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.Type(currentPage: number) => void-
onPageSizeChangeCalled when the page size changes.Type(pageSize: number) => void-
pageSizeNumber of items per page, bound with bind:pageSize; the choice made in the size changer is written back. Falls back to the first item of pageSizeOpts.number-
pageSizeOptsOptions of the size changer; the current page size is inserted in order when it is not among them.number[][10, 20, 40, 100]
popoverPositionPosition of the omitted pages popover and the size changer dropdown; not used by the small size.Position-
preventPageChangeOnPageSizeChangeKeeps the current page when the page size changes; the consumer picks the page in onPageSizeChange.booleanfalse
prevTextString or snippet that replaces the previous page icon. A string or a plain-text snippet names the button, and any other content (an icon, an element) keeps the locale name; an empty snippet leaves the button empty, an empty string shows the default icon.string | Snippet-
showQuickJumperWhether to show the quick jump input; disabled when there are fewer than 2 pages.booleanfalse
showSizeChangerWhether to show the size changer; not rendered when size is small.booleanfalse
showTotalWhether to show the total number of pages; not shown when size is small.booleanfalse
sizeSize: default or small.'small' | 'default'"default"
totalTotal number of items.number1

class, style and native attributes and events (such as id, aria-*, data-*, onclick) land on the root ul, for 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翻页器页码选中态字重