Skip to content

Commit ccd1163

Browse files
committed
expand examples & improve url guardrails
1 parent bb1170a commit ccd1163

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

frontend/src/components/ui/pagination.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,19 @@ export type PageChangeEvent = CustomEvent<PageChangeDetail>;
2828
/**
2929
* Pagination
3030
*
31+
* Persists via a search param in the URL. Defaults to `page`, but can be set with the `name` attribute.
32+
*
3133
* Usage example:
3234
* ```ts
33-
* <btrix-pagination totalCount="11" @page-change=${this.console.log}>
35+
* <btrix-pagination totalCount="11" @page-change=${console.log}>
36+
* </btrix-pagination>
37+
* ```
38+
*
39+
* You can have multiple paginations on one page by setting different names:
40+
* ```ts
41+
* <btrix-pagination name="page-a" totalCount="11" @page-change=${console.log}>
42+
* </btrix-pagination>
43+
* <btrix-pagination name="page-b" totalCount="2" @page-change=${console.log}>
3444
* </btrix-pagination>
3545
* ```
3646
*
@@ -139,7 +149,13 @@ export class Pagination extends LitElement {
139149

140150
@state()
141151
public get page() {
142-
return parsePage(this.searchParams.searchParams.get(this.name));
152+
return Math.min(
153+
1,
154+
Math.max(
155+
this.totalCount,
156+
parsePage(this.searchParams.searchParams.get(this.name)),
157+
),
158+
);
143159
}
144160

145161
@property({ type: String })

0 commit comments

Comments
 (0)