Skip to content

Pagination

The Pagination component provides a UI control for navigating between multiple pages. It supports optional numbered indicators, looping behavior, and customizable navigation controls.

It’s ideal for interfaces such as menus, level selectors, or any UI where page-based navigation is required.

To use Pagination, specify the total number of pages with pageSize and the current page index with pageIndex.

import Pagination from '@components/Basic/Pagination/Pagination';
const App = () => {
return (
<Pagination pageSize={10} pageIndex={3} />
)
};
export default App;
Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply directly to the component’s root element.
classstring""Additional CSS classes to apply to the component.
pageSizenumberrequiredTotal number of pages.
pageIndexnumberrequiredThe currently selected page index (1-based).
loopbooleanfalseEnables wrap-around navigation from last to first page and vice versa.
hasNumbersbooleanfalseIf true, displays page numbers inside each page indicator.
refPaginationRef | undefinedundefinedProvides access to the pagination element and control methods.
onChange(index: number) => voidundefinedCalled whenever the selected page changes, providing the new index.

To interact with the Pagination programmatically, you can use the PaginationRef interface. This interface provides properties and methods to access and manipulate the component’s state.

PropertyTypeDescription
elementHTMLDivElementThe root DOM element of the pagination component.
pageIndexAccessor<number>The current page index.
pageSizeAccessor<number>The total number of pages.
MethodParametersReturn ValueDescription
changeIndexindex: numbervoidProgrammatically change to a specific page.
nextPageNonevoidNavigate to the next page.
previousPageNonevoidNavigate to the previous page.

Use Pagination.Control to customize the visual appearance of the left/right arrow buttons.

By default, the control consists of two arrow buttons for navigating to the previous or next page.

You can apply additional CSS classes and styles to modify the appearance of the default arrows.

If you want to replace the default arrows with a custom control, you can provide children using any valid JSX syntax.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles to apply to the default arrow elements.
classstring""Additional CSS classes for the default arrow elements.
childrenJSX.Element""Custom content to replace the default arrow controls.
hidden-classstring""CSS class to override the default behavior when the control is hidden. If loop is not enabled, the left control will be hidden/disabled when the first option is selected, and the right control will behave similarly for the last option.
.control-hidden {
pointer-events: none;
opacity: 0.1;
}
import Pagination from '@components/Basic/Pagination/Pagination';
const App = () => {
return (
<Pagination pageSize={4} pageIndex={1}>
<Pagination.Control style={{"background-color": "white"}} />
</Pagination>
);
};
import Pagination from '@components/Basic/Pagination/Pagination';
import MyArrow from '@assets/icons/my-arrow.svg?component-solid';
const App = () => {
return (
<Pagination pageSize={4} pageIndex={1}>
<Pagination.Control hidden-class="control-hidden">
<MyArrow style={{ stroke: 'white' }} />
</Pagination.Control>
</Pagination>
);
};

The Pagination.Item slot allows you to customize the appearance of each individual page indicator (dot, number, etc.).

By default, each item is rendered as a simple clickable circle. You can use this slot to style them with custom colors, shapes, and sizes.

Prop NameTypeDefaultDescription
styleJSX.CSSProperties{}Inline styles applied to every item.
classstring""Additional CSS classes for styling the pagination items.
selected-classstring""CSS class to override the default styles of the selected item.
import Pagination from '@components/Basic/Pagination/Pagination';
const App = () => {
return (
<Pagination pageSize={15} pageIndex={1} hasNumbers>
<Pagination.Item
class="custom-item"
style={{'background-color': 'green'}}
selected-class="custom-selected" />
</Pagination>
);
};
export default App;

Use the onChange prop to react to user navigation. This callback is triggered whenever the active page changes, and it receives the updated page index as a parameter.

  1. Pass a callback function to the onChange prop.
  2. Use the page index in the callback to trigger data fetching or other logic.
import Pagination from '@components/Basic/Pagination/Pagination';
const App = () => {
const fetchPageData = (page: number) => {
// dynamically fetch the data
console.log('Page changed to:', page);
}
return (
<Pagination onChange={fetchPageData} pageSize={10} pageIndex={3} />
)
};
export default App;

You can also control the pagination programmatically using a component ref. This is useful when integrating keyboard, gamepad, or other custom navigation systems.

  1. Declare a ref of type PaginationRef and pass it to the Pagination component.
  2. Call ref.nextPage() or ref.previousPage() in response to keyboard events.
import { onMount } from 'solid-js';
import Pagination, { PaginationRef } from '@components/Basic/Pagination/Pagination';
const App = () => {
let ref!: PaginationRef;
const handleKeydown = (e: KeyboardEvent) => {
if (e.keyCode === 37) { // Left arrow
ref.previousPage();
} else if (e.keyCode === 39) { // Right arrow
ref.nextPage();
}
};
onMount(() => {
window.addEventListener('keydown', handleKeydown);
// Cleanup on unmount
return () => window.removeEventListener('keydown', handleKeydown);
});
return (
<Pagination
ref={ref}
pageSize={6}
pageIndex={1}
onChange={(page) => console.log('Page:', page)}
/>
);
};
export default App;