Pagination
Facilitates navigation between pages.
Showing 0 - 10
Structure
Managing Page State
Bits UI offers several approaches to manage and synchronize the Pagination's page state, catering to different levels of control and integration needs.
1. Two-Way Binding
For seamless state synchronization, use Svelte's bind:page
directive. This method automatically keeps your local state in sync with the component's internal state.
Key Benefits
- Simplifies state management
- Automatically updates
myPage
when the internal state changes (e.g., via clicking on a page button) - Allows external control (e.g., changing the page via a separate button/programmatically)
2. Change Handler
For more granular control or to perform additional logic on state changes, use the onPageChange
prop. This approach is useful when you need to execute custom logic alongside state updates.
Use Cases
- Implementing custom behaviors on page change
- Integrating with external state management solutions
- Triggering side effects (e.g., logging, data fetching)
3. Fully Controlled
For complete control over the component's pressed state, use the controlledPage
prop. This approach requires you to manually manage the state, giving you full control over when and how the component responds to change events.
To implement controlled state:
- Set the
controlledPage
prop totrue
on thePagination.Root
component. - Provide a
page
prop toPagination.Root
, which should be a variable holding the current state. - Implement an
onPageChange
handler to update the state when the internal state changes.
When to Use
- Implementing complex logic
- Coordinating multiple UI elements
- Debugging state-related issues
Note
While powerful, fully controlled state should be used judiciously as it increases complexity and can cause unexpected behaviors if not handled carefully.
For more in-depth information on controlled components and advanced state management techniques, refer to our Controlled State documentation.
Ellipsis
The pages
snippet prop consists of two types of items: 'page'
and 'ellipsis'
. The 'page'
type represents an actual page number, while the 'ellipsis'
type represents a placeholder for rendering an ellipsis between pages.
API Reference
The root pagination component which contains all other pagination components.
Property | Type | Description |
---|---|---|
count required | number | The total number of items. Default: undefined |
page $bindable | number | The selected page. You can bind this to a variable to control the selected page from outside the component. Default: undefined |
onPageChange | function | A function called when the selected page changes. Default: undefined |
controlledPage | boolean | Whether or not the page state is controlled or not. If Default: false |
perPage | number | The number of items per page. Default: 1 |
siblingCount | number | The number of page triggers to show on either side of the current page. Default: 1 |
loop | boolean | Whether or not the pagination should loop through the items when reaching the end while navigating with the keyboard. Default: false |
orientation | enum | The orientation of the pagination. This determines how keyboard navigation will work with the component. Default: horizontal |
ref $bindable | HTMLDivElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See Child Snippet docs for more information. Default: undefined |
A button that triggers a page change.
Property | Type | Description |
---|---|---|
page | PageItem | The page item this component represents. Default: undefined |
ref $bindable | HTMLButtonElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See Child Snippet docs for more information. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-selected | '' | Present on the current page element. |
data-pagination-page | '' | Present on the page trigger element. |
The previous button of the pagination.
Property | Type | Description |
---|---|---|
ref $bindable | HTMLButtonElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See Child Snippet docs for more information. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-pagination-prev-button | '' | Present on the previous button element. |
The next button of the pagination.
Property | Type | Description |
---|---|---|
ref $bindable | HTMLButtonElement | The underlying DOM element being rendered. You can bind to this to get a reference to the element. Default: undefined |
children | Snippet | The children content to render. Default: undefined |
child | Snippet | Use render delegation to render your own element. See Child Snippet docs for more information. Default: undefined |
Data Attribute | Value | Description |
---|---|---|
data-pagination-next-button | '' | Present on the next button element. |