ui icon indicating copy to clipboard operation
ui copied to clipboard

feat: Add `disable` prop to pagination buttons.

Open ahkhanjani opened this issue 1 year ago • 1 comments

I'm specifically asking this for Previous and Next buttons because in a dynamic client-side pagination, you don't really want to remove and add them to the UI. I couldn't find any ways to disable them.

ahkhanjani avatar Jan 24 '24 12:01 ahkhanjani

I ran into the same issue with needing to disable the "Previous" and "Next" Links in dynamic client-side pagination, here is a potential solution using the PaginationPrevious component that worked for me:

  <PaginationItem>
          <PaginationPrevious
            href={createPageURL(currentPage - 1)}
            aria-disabled={currentPage <= 1}
            tabIndex={currentPage <= 1 ? -1 : undefined}
            className={
              currentPage <= 1 ? "pointer-events-none opacity-50" : undefined
            }
          />

This code disables the button visually and functionally when on the first page by:

  • Setting aria-disabled to true.
  • Setting tabIndex to -1.
  • Applying CSS classes: pointer-event-none and opacity-50.

I hope it helps :)

DariusLukasukas avatar Feb 02 '24 00:02 DariusLukasukas

This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you.

shadcn avatar Feb 25 '24 23:02 shadcn

reopen the issue

ahkhanjani avatar Feb 26 '24 10:02 ahkhanjani

reopen sesame

cgar420 avatar Apr 22 '24 00:04 cgar420

The workaround is to make the href undefined in specific scenarios... Here's my workaround:

<PaginationItem> <PaginationFirst href={currentPage === 1 ? undefined : ${href}?page=${currentPage > 1 ? currentPage - 1 : 1}} aria-disabled={currentPage === 1} className={ currentPage === 1 ? "hover:bg-transparent cursor-default hover:text-muted-foreground text-muted-foreground opacity-50" : "hover:cursor-pointer" } /> </PaginationItem>

nuclei272 avatar Jun 22 '24 22:06 nuclei272

<PaginationPrevious className={${!hasPreviousPage && 'active:bg-white opacity-60'}} href={!hasPreviousPage ? undefined : 'your url' } />

this one worked for me :)

fazal199 avatar Jul 12 '24 13:07 fazal199