fix(pagination): convert page variable to number type

The Select component coerces the page value into a string, which affects other components.
This commit is contained in:
Eric Liu 2020-09-14 07:20:48 -07:00
commit 0138910077
2 changed files with 17 additions and 2 deletions

View file

@ -12,6 +12,12 @@
{:else if story === 'skeleton'}
<PaginationSkeleton />
{:else}
<Pagination {...$$props}>Pagination</Pagination>
<Pagination
{...$$props}
on:update="{({ detail }) => {
console.log(detail);
}}">
Pagination
</Pagination>
{/if}
</div>

View file

@ -100,9 +100,18 @@
const dispatch = createEventDispatcher();
afterUpdate(() => {
dispatch("update", { pageSize: parseInt(pageSize), page: parseInt(page) });
dispatch("update", { pageSize, page });
});
$: {
if (typeof page !== "number") {
page = Number(page);
}
if (typeof pageSize !== "number") {
pageSize = Number(pageSize);
}
}
$: totalPages = Math.max(Math.ceil(totalItems / pageSize), 1);
$: selectItems = Array.from({ length: totalPages }, (_, i) => i);
$: backButtonDisabled = disabled || page === 1;