Fix Pagination disabled guards
This commit is contained in:
parent
a9a9506f98
commit
824d12ba9a
@ -1,5 +1,5 @@
|
|||||||
import type { JSX } from "solid-js";
|
import type { JSX } from "solid-js";
|
||||||
import { For } from "solid-js";
|
import { For, splitProps } from "solid-js";
|
||||||
import { usePaginationContext } from "./pagination-context";
|
import { usePaginationContext } from "./pagination-context";
|
||||||
|
|
||||||
/** Represents a single item in the pagination list. */
|
/** 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.
|
* Calculates which pages to show based on page, totalPages, and siblingCount.
|
||||||
*/
|
*/
|
||||||
export function PaginationItems(props: PaginationItemsProps): JSX.Element {
|
export function PaginationItems(props: PaginationItemsProps): JSX.Element {
|
||||||
|
const [local] = splitProps(props, ["children"]);
|
||||||
const ctx = usePaginationContext();
|
const ctx = usePaginationContext();
|
||||||
const items = () => buildItems(ctx.page(), ctx.totalPages(), ctx.siblingCount());
|
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>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,8 +15,9 @@ export function PaginationNext(props: PaginationNextProps): JSX.Element {
|
|||||||
const isDisabled = () => ctx.page() >= ctx.totalPages();
|
const isDisabled = () => ctx.page() >= ctx.totalPages();
|
||||||
|
|
||||||
const handleClick: JSX.EventHandler<HTMLButtonElement, MouseEvent> = (e) => {
|
const handleClick: JSX.EventHandler<HTMLButtonElement, MouseEvent> = (e) => {
|
||||||
|
if (isDisabled()) return;
|
||||||
if (typeof local.onClick === "function") local.onClick(e);
|
if (typeof local.onClick === "function") local.onClick(e);
|
||||||
if (!isDisabled()) ctx.onPageChange(ctx.page() + 1);
|
ctx.onPageChange(ctx.page() + 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@ -15,8 +15,9 @@ export function PaginationPrevious(props: PaginationPreviousProps): JSX.Element
|
|||||||
const isDisabled = () => ctx.page() <= 1;
|
const isDisabled = () => ctx.page() <= 1;
|
||||||
|
|
||||||
const handleClick: JSX.EventHandler<HTMLButtonElement, MouseEvent> = (e) => {
|
const handleClick: JSX.EventHandler<HTMLButtonElement, MouseEvent> = (e) => {
|
||||||
|
if (isDisabled()) return;
|
||||||
if (typeof local.onClick === "function") local.onClick(e);
|
if (typeof local.onClick === "function") local.onClick(e);
|
||||||
if (!isDisabled()) ctx.onPageChange(ctx.page() - 1);
|
ctx.onPageChange(ctx.page() - 1);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user