mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
Correct page number when dispatching update (#911)
* Correct page number when dispatching update When in last page of data and the page size get changed to a bigger size the current page number will be out of range of total pages. This code will set the page number in range of total pages. * fix(pagination): page value should not exceed totalPages Co-authored-by: metonym <ericyl.us@gmail.com>
This commit is contained in:
parent
914f9af3be
commit
1aad3153b5
1 changed files with 7 additions and 1 deletions
|
@ -70,7 +70,7 @@
|
||||||
/** Set an id for the top-level element */
|
/** Set an id for the top-level element */
|
||||||
export let id = "ccs-" + Math.random().toString(36);
|
export let id = "ccs-" + Math.random().toString(36);
|
||||||
|
|
||||||
import { createEventDispatcher } from "svelte";
|
import { afterUpdate, createEventDispatcher } from "svelte";
|
||||||
import CaretLeft16 from "../icons/CaretLeft16.svelte";
|
import CaretLeft16 from "../icons/CaretLeft16.svelte";
|
||||||
import CaretRight16 from "../icons/CaretRight16.svelte";
|
import CaretRight16 from "../icons/CaretRight16.svelte";
|
||||||
import Button from "../Button/Button.svelte";
|
import Button from "../Button/Button.svelte";
|
||||||
|
@ -79,6 +79,12 @@
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
|
afterUpdate(() => {
|
||||||
|
if (page > totalPages) {
|
||||||
|
page = totalPages;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (typeof page !== "number") {
|
if (typeof page !== "number") {
|
||||||
page = Number(page);
|
page = Number(page);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue