Fix Pagination disabled guards

This commit is contained in:
Mats Bosson 2026-03-29 08:53:07 +07:00
parent a9a9506f98
commit 824d12ba9a
3 changed files with 7 additions and 4 deletions

View File

@ -1,5 +1,5 @@
import type { JSX } from "solid-js";
import { For } from "solid-js";
import { For, splitProps } from "solid-js";
import { usePaginationContext } from "./pagination-context";
/** Represents a single item in the pagination list. */
@ -50,7 +50,8 @@ function buildItems(page: number, total: number, siblings: number): PaginationIt
* Calculates which pages to show based on page, totalPages, and siblingCount.
*/
export function PaginationItems(props: PaginationItemsProps): JSX.Element {
const [local] = splitProps(props, ["children"]);
const ctx = usePaginationContext();
const items = () => buildItems(ctx.page(), ctx.totalPages(), ctx.siblingCount());
return <For each={items()}>{(item) => props.children(item)}</For>;
return <For each={items()}>{(item) => local.children(item)}</For>;
}

View File

@ -15,8 +15,9 @@ export function PaginationNext(props: PaginationNextProps): JSX.Element {
const isDisabled = () => ctx.page() >= ctx.totalPages();
const handleClick: JSX.EventHandler<HTMLButtonElement, MouseEvent> = (e) => {
if (isDisabled()) return;
if (typeof local.onClick === "function") local.onClick(e);
if (!isDisabled()) ctx.onPageChange(ctx.page() + 1);
ctx.onPageChange(ctx.page() + 1);
};
return (

View File

@ -15,8 +15,9 @@ export function PaginationPrevious(props: PaginationPreviousProps): JSX.Element
const isDisabled = () => ctx.page() <= 1;
const handleClick: JSX.EventHandler<HTMLButtonElement, MouseEvent> = (e) => {
if (isDisabled()) return;
if (typeof local.onClick === "function") local.onClick(e);
if (!isDisabled()) ctx.onPageChange(ctx.page() - 1);
ctx.onPageChange(ctx.page() - 1);
};
return (