Skip to content

Commit

Permalink
fix: pagination clicking page triggers form submit
Browse files Browse the repository at this point in the history
When used in a form, the pagination triggers a form submit.

Changed pagination links to be buttons with type button instead of the
default submit.

Closes #702
  • Loading branch information
BarryS42 authored and gidomanders committed Jan 16, 2024
1 parent daca395 commit 58ec44a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/core/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,23 @@ export function Pagination<T>({
{content.map((item, index) => (
<PaginationItem active={item === current} key={index}>
{item === '...' ? (
<PaginationLink className="disabled" disabled={true}>
<PaginationLink
className="disabled"
disabled={true}
type="button"
>
{item}
</PaginationLink>
) : (
<PaginationLink onClick={() => onChange(item)}>
<PaginationLink onClick={() => onChange(item)} type="button">
{item}
</PaginationLink>
)}
</PaginationItem>
))}
{showPreviousAndNextButtons ? (
<PaginationItem disabled={last}>
<PaginationLink onClick={() => onChange(current + 1)}>
<PaginationLink onClick={() => onChange(current + 1)} type="button">
<Icon icon="arrow_forward" size={14} />
</PaginationLink>
</PaginationItem>
Expand Down
24 changes: 24 additions & 0 deletions src/core/Pagination/__snapshots__/Pagination.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ exports[`Component: Pagination ui first page 1`] = `
>
<button
class="page-link"
type="button"
>
1
</button>
Expand All @@ -40,6 +41,7 @@ exports[`Component: Pagination ui first page 1`] = `
>
<button
class="page-link"
type="button"
>
2
</button>
Expand All @@ -49,6 +51,7 @@ exports[`Component: Pagination ui first page 1`] = `
>
<button
class="page-link"
type="button"
>
3
</button>
Expand All @@ -59,6 +62,7 @@ exports[`Component: Pagination ui first page 1`] = `
<button
class="disabled page-link"
disabled=""
type="button"
>
...
</button>
Expand All @@ -68,6 +72,7 @@ exports[`Component: Pagination ui first page 1`] = `
>
<button
class="page-link"
type="button"
>
8
</button>
Expand All @@ -77,6 +82,7 @@ exports[`Component: Pagination ui first page 1`] = `
>
<button
class="page-link"
type="button"
>
9
</button>
Expand All @@ -86,6 +92,7 @@ exports[`Component: Pagination ui first page 1`] = `
>
<button
class="page-link"
type="button"
>
10
</button>
Expand All @@ -95,6 +102,7 @@ exports[`Component: Pagination ui first page 1`] = `
>
<button
class="page-link"
type="button"
>
<i
class="icon material-icons"
Expand Down Expand Up @@ -146,6 +154,7 @@ exports[`Component: Pagination ui last page 1`] = `
>
<button
class="page-link"
type="button"
>
1
</button>
Expand All @@ -155,6 +164,7 @@ exports[`Component: Pagination ui last page 1`] = `
>
<button
class="page-link"
type="button"
>
2
</button>
Expand All @@ -164,6 +174,7 @@ exports[`Component: Pagination ui last page 1`] = `
>
<button
class="page-link"
type="button"
>
3
</button>
Expand All @@ -174,6 +185,7 @@ exports[`Component: Pagination ui last page 1`] = `
<button
class="disabled page-link"
disabled=""
type="button"
>
...
</button>
Expand All @@ -183,6 +195,7 @@ exports[`Component: Pagination ui last page 1`] = `
>
<button
class="page-link"
type="button"
>
8
</button>
Expand All @@ -192,6 +205,7 @@ exports[`Component: Pagination ui last page 1`] = `
>
<button
class="page-link"
type="button"
>
9
</button>
Expand All @@ -201,6 +215,7 @@ exports[`Component: Pagination ui last page 1`] = `
>
<button
class="page-link"
type="button"
>
10
</button>
Expand All @@ -210,6 +225,7 @@ exports[`Component: Pagination ui last page 1`] = `
>
<button
class="page-link"
type="button"
>
<i
class="icon material-icons"
Expand Down Expand Up @@ -261,6 +277,7 @@ exports[`Component: Pagination ui middle 1`] = `
>
<button
class="page-link"
type="button"
>
1
</button>
Expand All @@ -271,6 +288,7 @@ exports[`Component: Pagination ui middle 1`] = `
<button
class="disabled page-link"
disabled=""
type="button"
>
...
</button>
Expand All @@ -280,6 +298,7 @@ exports[`Component: Pagination ui middle 1`] = `
>
<button
class="page-link"
type="button"
>
4
</button>
Expand All @@ -289,6 +308,7 @@ exports[`Component: Pagination ui middle 1`] = `
>
<button
class="page-link"
type="button"
>
5
</button>
Expand All @@ -298,6 +318,7 @@ exports[`Component: Pagination ui middle 1`] = `
>
<button
class="page-link"
type="button"
>
6
</button>
Expand All @@ -308,6 +329,7 @@ exports[`Component: Pagination ui middle 1`] = `
<button
class="disabled page-link"
disabled=""
type="button"
>
...
</button>
Expand All @@ -317,6 +339,7 @@ exports[`Component: Pagination ui middle 1`] = `
>
<button
class="page-link"
type="button"
>
10
</button>
Expand All @@ -326,6 +349,7 @@ exports[`Component: Pagination ui middle 1`] = `
>
<button
class="page-link"
type="button"
>
<i
class="icon material-icons"
Expand Down
8 changes: 8 additions & 0 deletions src/form/ModalPicker/__snapshots__/ModalPicker.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ exports[`Component: ModalPicker ui default 1`] = `
>
<button
class="page-link"
type="button"
>
1
</button>
Expand All @@ -125,6 +126,7 @@ exports[`Component: ModalPicker ui default 1`] = `
>
<button
class="page-link"
type="button"
>
2
</button>
Expand All @@ -134,6 +136,7 @@ exports[`Component: ModalPicker ui default 1`] = `
>
<button
class="page-link"
type="button"
>
3
</button>
Expand All @@ -143,6 +146,7 @@ exports[`Component: ModalPicker ui default 1`] = `
>
<button
class="page-link"
type="button"
>
<i
class="icon material-icons"
Expand Down Expand Up @@ -364,6 +368,7 @@ exports[`Component: ModalPicker ui loading 1`] = `
>
<button
class="page-link"
type="button"
>
1
</button>
Expand All @@ -373,6 +378,7 @@ exports[`Component: ModalPicker ui loading 1`] = `
>
<button
class="page-link"
type="button"
>
2
</button>
Expand All @@ -382,6 +388,7 @@ exports[`Component: ModalPicker ui loading 1`] = `
>
<button
class="page-link"
type="button"
>
3
</button>
Expand All @@ -391,6 +398,7 @@ exports[`Component: ModalPicker ui loading 1`] = `
>
<button
class="page-link"
type="button"
>
<i
class="icon material-icons"
Expand Down

0 comments on commit 58ec44a

Please sign in to comment.