apps/v4/content/docs/components/base/pagination.mdx
npx shadcn@latest add pagination
<Step>Copy and paste the following code into your project.</Step>
<ComponentSource name="pagination" title="components/ui/pagination.tsx" styleName="base-nova" />
<Step>Update the import paths to match your project setup.</Step>
</Steps> </TabsContent> </CodeTabs>import {
Pagination,
PaginationContent,
PaginationEllipsis,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination"
<Pagination>
<PaginationContent>
<PaginationItem>
<PaginationPrevious href="#" />
</PaginationItem>
<PaginationItem>
<PaginationLink href="#">1</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="#" isActive>
2
</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationLink href="#">3</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationEllipsis />
</PaginationItem>
<PaginationItem>
<PaginationNext href="#" />
</PaginationItem>
</PaginationContent>
</Pagination>
A simple pagination with only page numbers.
<ComponentPreview styleName="base-nova" name="pagination-simple" />Use just the previous and next buttons without page numbers. This is useful for data tables with a rows per page selector.
<ComponentPreview styleName="base-nova" name="pagination-icons-only" />By default the <PaginationLink /> component will render an <a /> tag.
To use the Next.js <Link /> component, make the following updates to pagination.tsx.
+ import Link from "next/link"
- type PaginationLinkProps = ... & React.ComponentProps<"a">
+ type PaginationLinkProps = ... & React.ComponentProps<typeof Link>
const PaginationLink = ({...props }: ) => (
<PaginationItem>
- <a>
+ <Link>
// ...
- </a>
+ </Link>
</PaginationItem>
)
Note: We are making updates to the cli to automatically do this for you.
</Callout>To enable RTL support in shadcn/ui, see the RTL configuration guide.
<ComponentPreview styleName="base-nova" name="pagination-rtl" direction="rtl" />If you're upgrading from a previous version of the Pagination component, you'll need to apply the following updates to add the text prop:
<Step>Update PaginationPrevious.</Step>
function PaginationPrevious({
className,
+ text = "Previous",
...props
- }: React.ComponentProps<typeof PaginationLink>) {
+ }: React.ComponentProps<typeof PaginationLink> & { text?: string }) {
return (
<PaginationLink
aria-label="Go to previous page"
size="default"
className={cn("cn-pagination-previous", className)}
{...props}
>
<ChevronLeftIcon />
<span className="cn-pagination-previous-text hidden sm:block">
- Previous
+ {text}
</span>
</PaginationLink>
)
}
<Step>Update PaginationNext.</Step>
function PaginationNext({
className,
+ text = "Next",
...props
- }: React.ComponentProps<typeof PaginationLink>) {
+ }: React.ComponentProps<typeof PaginationLink> & { text?: string }) {
return (
<PaginationLink
aria-label="Go to next page"
size="default"
className={cn("cn-pagination-next", className)}
{...props}
>
- <span className="cn-pagination-next-text hidden sm:block">Next</span>
+ <span className="cn-pagination-next-text hidden sm:block">{text}</span>
<ChevronRightIcon />
</PaginationLink>
)
}