Demos
How to import
<script setup lang="ts">
import { Pagination } from '@fibrous/semi-ui-vue';
</script>
Basic Usage
Set the total number via total, set capacity per page via pageSize.
Code
<script setup lang="ts">
import { Pagination } from '@fibrous/semi-ui-vue';
</script>
<template>
<div>
<Pagination :style="{ marginBottom: '12px' }" :total="30" />
<Pagination :style="{ marginBottom: '12px' }" :total="80" />
<Pagination :style="{ marginBottom: '12px' }" :total="200" />
<Pagination :pageSize="30" :style="{ marginBottom: '12px' }" :total="80" />
</div>
</template>disabled
Disabled via the disabled setting
Code
<script setup lang="ts">
import { Pagination } from '@fibrous/semi-ui-vue';
</script>
<template>
<Pagination disabled :style="{ marginBottom: '12px' }" :total="30" />
</template>Show total page number
Use the showTotal property to control whether the total number of pages is shown.
- 总页数:8
- 总页数:20
Code
<script setup lang="ts">
import { Pagination } from '@fibrous/semi-ui-vue';
</script>
<template>
<div>
<Pagination showTotal style="margin-bottom: 12px" :total="80" />
<Pagination showTotal style="margin-bottom: 12px" :total="200" />
</div>
</template>Specify current page number
You can specify the currently active page number via defaultCurrentPage.
- 总页数:8
Code
<script setup lang="ts">
import { Pagination } from '@fibrous/semi-ui-vue';
</script>
<template>
<div>
<Pagination :defaultCurrentPage="3" showTotal :total="80" />
</div>
</template>Capacity switching per page
By setting showSizeChanger for true, allowing quick switching of capacity per page via the Select component
- 每页条数:10
- 每页条数:10
Code
<script setup lang="ts">
import { Pagination } from '@fibrous/semi-ui-vue';
</script>
<template>
<div>
<Pagination showSizeChanger style="margin-bottom: 12px" :total="80" />
<Pagination showSizeChanger :total="300" />
</div>
</template>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 setup lang="ts">
import { Pagination } from '@fibrous/semi-ui-vue';
</script>
<template>
<div>
<Pagination showQuickJumper style="margin-bottom: 12px" :total="80" />
<Pagination showQuickJumper :total="300" />
</div>
</template>Page number controlled
Bind the page number with v-model:currentPage and the pager is a controlled component: the current active page number depends entirely on the bound value. You can also pass only currentPage and update it yourself from @pageChange.
Code
<script setup lang="ts">
import { ref } from 'vue';
import { Pagination } from '@fibrous/semi-ui-vue';
const page = ref(3);
</script>
<template>
<Pagination v-model:currentPage="page" :total="200" />
</template>Preset capacity per page
Specify an optional value for switching the capacity per page by using the pageSizeOpts array
- 每页条数:50
- 每页条数:10
Code
<script setup lang="ts">
import { Pagination } from '@fibrous/semi-ui-vue';
</script>
<template>
<div>
<Pagination :pageSizeOpts="[50, 80, 90, 200]" showSizeChanger style="margin-bottom: 12px" :total="300" />
<Pagination :pageSizeOpts="[10, 20, 50, 200]" showSizeChanger :total="300" />
</div>
</template>Mini version
Show mini pagination via size properties.
- 1/9
Code
<script setup lang="ts">
import { Pagination } from '@fibrous/semi-ui-vue';
</script>
<template>
<Pagination size="small" :total="90" />
</template>Turn on hoverShowPageSelect to open the page list by hovering the page text and switch pages quickly
Code
<script setup lang="ts">
import { Pagination } from '@fibrous/semi-ui-vue';
</script>
<template>
<Pagination hoverShowPageSelect size="small" :total="90" />
</template>API reference
Props
| Property | Description | Type | Default |
|---|---|---|---|
| total | Total number of items. | number | semiDefault("Pagination", "total", 1) |
| showTotal | Whether to show the total number of pages; not shown when size is small. | boolean | semiDefault("Pagination", "showTotal", false) |
| pageSize | Number 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 the changer's result back with v-model:pageSize does not reset the page. | number | semiGlobalDefault("Pagination", "pageSize") |
| pageSizeOpts | Options of the size changer; the current page size is inserted in order when it is not among them. | number[] | TypesemiDefault("Pagination", "pageSizeOpts", [...numbers.PAGE_SIZE_OPTION]) |
| size | Size: default or small. | "small" | "default" | semiDefault("Pagination", "size", "default") |
| currentPage | Current page, bound with v-model:currentPage. Once set the pagination is controlled; when undefined the component manages the page itself. | number | semiGlobalDefault("Pagination", "currentPage") |
| defaultCurrentPage | Initial page when not controlled. | number | semiDefault("Pagination", "defaultCurrentPage", 1) |
| showSizeChanger | Whether to show the size changer; has no effect when size is small. When it is shown, hideOnSinglePage no longer takes effect. | boolean | semiDefault("Pagination", "showSizeChanger", false) |
| showQuickJumper | Whether to show the quick jump input; disabled when there are fewer than 2 pages. | boolean | semiDefault("Pagination", "showQuickJumper", false) |
| popoverPosition | Position 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 by the small size. | Type"top" | "bottom" | "left" | "right" | "topLeft" | "topRight" | "leftTop" | "leftBottom" | "rightTop" | "rightBottom" | "bottomLeft" | "bottomRight" | "leftTopOver" | "rightTopOver" | "leftBottomOver" | "rightBottomOver" | semiGlobalDefault("Pagination", "popoverPosition") |
| hideOnSinglePage | Whether to hide the pagination when there are fewer than 2 pages; has no effect while the size changer is shown. | boolean | semiDefault("Pagination", "hideOnSinglePage", false) |
| hoverShowPageSelect | Only for size small: the page list opens when the page text is hovered or focused. | boolean | semiGlobalDefault("Pagination", "hoverShowPageSelect") |
| disabled | Whether disabled. | boolean | semiDefault("Pagination", "disabled", false) |
| preventPageChangeOnPageSizeChange | Keeps the current page when the page size changes; the consumer picks the page in pageSizeChange. | boolean | semiDefault("Pagination", "preventPageChangeOnPageSizeChange", false) |
Events
| Event | Description | Callback parameters |
|---|---|---|
| update:currentPage | Emitted when the page changes, for v-model:currentPage. | [currentPage: number] |
| update:pageSize | Emitted when the page size changes, for v-model:pageSize. | [pageSize: number] |
| pageChange | Emitted when the page changes. | [currentPage: number] |
| pageSizeChange | Emitted when the page size changes. | [pageSize: number] |
| change | Emitted when the page or the page size changes. | [currentPage: number, pageSize: number] |
Slots
| Slot | Description | Scope parameters |
|---|---|---|
| prevText | Replaces the previous page icon. A plain text names the button, and any other content (an icon, an element) keeps the locale name; an empty slot keeps the default icon and the locale name. | any |
| nextText | Replaces the next page icon, named the same way as prevText. | any |
Exposes
| Name | Description | Type |
|---|---|---|
| None |
class, style and native attributes (id, aria-*, data-*, event listeners) fall through attrs onto the root ul, for both the default and the small size. change is a declared component event, so @change receives only the page and the page size, never the native change event bubbling up from the quick jump input. A template ref gives the component instance; the root element is its $el.
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 anliin 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; withprevTextornextText(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 nativedisabled - 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, andEnterorSpaceturns the page; - Keyboard focus on "…", or on the page text in small mode with
hoverShowPageSelect, opens the list of the omitted pages:Down Arrowfocuses the first page in the list,Up Arrowfocuses the last one;TabandShift + Tabmove in the list,EnterorSpacejumps to the page;Esccloses the list and returns focus to the trigger button.
Design Tokens
| Sass variable | Value | Usage |
|---|---|---|
| $transition_duration-pagination_item-bg | var(--semi-transition_duration-none) | 翻页器页码-背景色-动画持续时间 |
| $transition_function-pagination_item-bg | var(--semi-transition_function-easeIn) | 翻页器页码-背景色-过渡曲线 |
| $transition_delay-pagination_item-bg | var(--semi-transition_delay-none) | 翻页器页码-背景色-延迟时间 |
| $transition_duration-pagination_item-text | var(--semi-transition_duration-none) | 翻页器页码文本-背景色-动画持续时间 |
| $transition_function-pagination_item-text | var(--semi-transition_function-easeIn) | 翻页器页码文本-背景色-过渡曲线 |
| $transition_delay-pagination_item-text | var(--semi-transition_delay-none) | 翻页器页码文本-背景色-延迟时间 |
| $transform_scale-pagination_item | var(--semi-transform_scale-none) | 翻页器item-放大 |
| $color-pagination-text-default | var(--semi-color-text-2) | 翻页器总页数文本颜色 |
| $color-pagination_item-text-default | var(--semi-color-text-0) | 翻页器 页码 文本颜色 |
| $color-pagination_item-icon-default | var(--semi-color-tertiary) | 翻页器 页码 图标颜色 |
| $color-pagination_item-text-hover | var(--semi-color-text-0) | 翻页器 页码 悬浮态文本颜色 |
| $color-pagination_item-bg-hover | var(--semi-color-fill-0) | 翻页器 页码 悬浮态背景颜色 |
| $color-pagination_item-text-active | var(--semi-color-text-0) | 翻页器 页码 按下态文字颜色 |
| $color-pagination_item-bg-active | var(--semi-color-fill-1) | 翻页器 页码 按下态背景颜色 |
| $color-pagination_item-text-disabled | var(--semi-color-disabled-text) | 翻页器 页码 禁用态文字颜色 |
| $color-pagination_item-icon-disabled | var(--semi-color-disabled-text) | 翻页器 页码 禁用态图标颜色 |
| $color-pagination_item-bg-disabled | transparent | 翻页器 页码 禁用态背景颜色 |
| $color-pagination_item-bg-selected-disabled | var(--semi-color-disabled-fill) | 翻页器 页码 选中禁用态背景颜色 |
| $color-pagination_item-text-selected | var(--semi-color-primary) | 翻页器 页码 选中态文字颜色 |
| $color-pagination_item-bg-selected | var(--semi-color-primary-light-default) | 翻页器 页码 选中态背景颜色 |
| $color-pagination_quickjump_text-disabled | var(--semi-color-disabled-text) | 翻页器 快速跳转禁用态文字颜色 |
| $color-pagination_item-border-default | transparent | 翻页器 页码 默认边框颜色 |
| $color-pagination_item-border-hover | transparent | 翻页器 页码 悬浮边框颜色 |
| $color-pagination_item-border-active | transparent | 翻页器 页码 激活边框颜色 |
| $color-pagination_item-border-selected | transparent | 翻页器 页码 选中边框颜色 |
| $color-pagination_item-border-disabled | transparent | 翻页器 页码 禁用边框颜色 |
| $height-pagination_item | 32px | 翻页器 页码高度 |
| $width-pagination_item-minWidth | 32px | 翻页器 页码最小宽度 |
| $width-pagination_item_small-minWidth | 44px | 迷你翻页器 页码最小宽度 |
| $width-pagination_quickjump_input_width | 50px | 快速跳转输入框宽度 |
| $width-pagination_item_border | 0px | 翻页器 页码 默认边框宽度 |
| $spacing-pagination-padding | 0 | 翻页器内边距 |
| $spacing-pagination_small-paddingY | 0 | 迷你翻页器垂直内边距 |
| $spacing-pagination_small-paddingX | 0 | 迷你翻页器水平内边距 |
| $spacing-pagination_item-marginLeft | $spacing-extra-tight | 翻页器页码左侧外边距 |
| $spacing-pagination_item-marginRight | $spacing-extra-tight | 翻页器页码右侧外边距 |
| $spacing-pagination_item_small-margin | 0 | 迷你翻页器页码外边距 |
| $spacing-pagination_reset_list-paddingTop | $spacing-extra-tight | |
| $spacing-pagination_reset_list-paddingBottom | $spacing-extra-tight | |
| $spacing-pagination_quickjump_marginLeft | 24px | 快速跳转左侧外边距 |
| $spacing-pagination_quickjump_input_marginLeft | 4px | 快速跳转输入框左侧外边距 |
| $spacing-pagination_quickjump_input_marginRight | 4px | 快速跳转输入框右侧外边距 |
| $radius-pagination_item | var(--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 | 翻页器页码选中态字重 |