Demos
How to import
import { Pagination } from '@fibrous/semi-ui-solid';
Basic Usage
Set the total number via total, set capacity per page via pageSize.
Code
import { Pagination } from '@fibrous/semi-ui-solid';
export default function PaginationDemo() {
return (
<div>
<Pagination total={30} style={{ 'margin-bottom': '12px' }} />
<Pagination total={80} style={{ 'margin-bottom': '12px' }} />
<Pagination total={200} style={{ 'margin-bottom': '12px' }} />
<Pagination total={80} pageSize={30} style={{ 'margin-bottom': '12px' }} />
</div>
);
}disabled
Disabled via the disabled setting
Code
import { Pagination } from '@fibrous/semi-ui-solid';
export default function PaginationDemo() {
return <Pagination total={30} disabled style={{ 'margin-bottom': '12px' }} />;
}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-solid';
export default function PaginationDemo() {
return (
<div>
<Pagination total={80} showTotal style={{ 'margin-bottom': '12px' }} />
<Pagination total={200} showTotal style={{ 'margin-bottom': '12px' }} />
</div>
);
}Specify current page number
You can specify the currently active page number via defaultCurrentPage.
- 总页数:8
Code
import { Pagination } from '@fibrous/semi-ui-solid';
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
- 每页条数:10
- 每页条数:10
Code
import { Pagination } from '@fibrous/semi-ui-solid';
export default function PaginationDemo() {
return (
<div>
<Pagination total={80} showSizeChanger style={{ 'margin-bottom': '12px' }} />
<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-solid';
export default function PaginationDemo() {
return (
<div>
<Pagination total={80} showQuickJumper style={{ 'margin-bottom': '12px' }} />
<Pagination total={300} showQuickJumper />
</div>
);
}Page number controlled
A passed currentPage makes the pagination controlled: the active page is entirely determined by that value, so write the new page from onPageChange back into your state to change it.
Code
import { createSignal } from 'solid-js';
import { Pagination } from '@fibrous/semi-ui-solid';
export default function PaginationDemo() {
const [page, setPage] = createSignal(3);
return <Pagination total={200} currentPage={page()} onPageChange={(currentPage) => setPage(currentPage)} />;
}Preset capacity per page
Specify an optional value for switching the capacity per page by using the pageSizeOpts array
- 每页条数:50
- 每页条数:10
Code
import { Pagination } from '@fibrous/semi-ui-solid';
export default function PaginationDemo() {
return (
<div>
<Pagination total={300} showSizeChanger style={{ 'margin-bottom': '12px' }} 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-solid';
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-solid';
export default function PaginationDemo() {
return <Pagination total={90} size="small" hoverShowPageSelect />;
}API reference
Props
| Property | Description | Type | Default |
|---|---|---|---|
| currentPage | Current 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 | - |
| defaultCurrentPage | Initial page when not controlled. | number | 1 |
| disabled | Whether disabled. | boolean | false |
| hideOnSinglePage | Whether to hide the pagination when there are fewer than 2 pages; has no effect while the size changer is shown. | boolean | false |
| hoverShowPageSelect | Only for size small: the page list opens when the page text is hovered or focused. | boolean | - |
| nextText | Replaces the content of the next page button, named the same way as prevText. | JSX.Element | - |
| onChange | Called when the page or the page size changes, with the page and the page size. | Type(currentPage: number, pageSize: number) => void | - |
| onPageChange | Called when the page changes, with the new page. | Type(currentPage: number) => void | - |
| onPageSizeChange | Called when the page size changes, with the new page size. | Type(newPageSize: number) => void | - |
| 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 it back from onChange does not reset the page. | number | - |
| pageSizeOpts | Options of the size changer; the current page size is inserted in order when it is not among them. | TypeArray<number> | [10, 20, 40, 100] |
| 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. | PopoverPosition | - |
| preventPageChangeOnPageSizeChange | Keeps the current page when the page size changes; the consumer picks the page in onPageSizeChange. | boolean | false |
| prevText | Replaces 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. | JSX.Element | - |
| showQuickJumper | Whether to show the quick jump input; disabled when there are fewer than 2 pages. | boolean | false |
| showSizeChanger | Whether to show the size changer; has no effect when size is small. When it is shown, hideOnSinglePage no longer takes effect. | boolean | false |
| showTotal | Whether to show the total number of pages; not shown when size is small. | boolean | false |
| size | Size: default or small. | 'small' | 'default' | "default" |
| total | Total number of items. | number | 1 |
class, style, ref 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 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 | 翻页器页码选中态字重 |