Skip to content

Commit 2bd449b

Browse files
committed
fix: reset pagination on first page
1 parent 21ab2e8 commit 2bd449b

File tree

1 file changed

+17
-13
lines changed
  • packages/components-vue/src/components/pagination

1 file changed

+17
-13
lines changed

packages/components-vue/src/components/pagination/Simple.vue

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,13 @@
2727
</li>
2828
<template v-if="currentPage.totalCount > currentPage.edges.length">
2929
<li>
30+
<!-- Reset at if coming from second page -->
3031
<ActionButtonToggle
3132
:theme="theme"
3233
:aria-label="t('previous')"
33-
:disabled="!currentPage.pageInfo.hasPreviousPage"
34+
:disabled="!pageInfo?.hasPreviousPage"
3435
round=":sm-inv"
35-
@click="currentPage && setAt(currentPage.pageInfo?.previousCursor)"
36+
@click="setAt(pageNumber > 2 ? pageInfo?.previousCursor : undefined)"
3637
>
3738
<IconFa name="arrow-left" />
3839
<IconFa name="arrow-left" regular />
@@ -43,9 +44,9 @@
4344
<ActionButtonToggle
4445
:theme="theme"
4546
:aria-label="t('next')"
46-
:disabled="!currentPage.pageInfo.hasNextPage"
47+
:disabled="!pageInfo?.hasNextPage"
4748
round=":sm-inv"
48-
@click="currentPage && setAt(currentPage.pageInfo?.nextCursor)"
49+
@click="setAt(pageInfo?.nextCursor)"
4950
>
5051
<span class="--hidden-full:sm-inv">{{ t("next") }}</span>
5152
<IconFa name="arrow-right" />
@@ -99,15 +100,8 @@
99100
const { first: defaultFirst } = inject<iPluginOptions>("xamu") || {};
100101
const { t } = useHelpers(useI18n);
101102
102-
/**
103-
* Set at
104-
* preserve route/pagination
105-
*
106-
* @replace
107-
*/
108-
function setAt(at?: string | number) {
109-
emit("update:model-value", { ...props.modelValue, at });
110-
}
103+
const pageInfo = computed(() => props.currentPage?.pageInfo);
104+
const pageNumber = computed(() => props.currentPage?.pageInfo?.pageNumber || 0);
111105
112106
/**
113107
* PaginationSimple first model
@@ -131,4 +125,14 @@
131125
132126
return pagesText;
133127
});
128+
129+
/**
130+
* Set at
131+
* preserve route/pagination
132+
*
133+
* @replace
134+
*/
135+
function setAt(at?: string | number) {
136+
emit("update:model-value", { ...props.modelValue, at });
137+
}
134138
</script>

0 commit comments

Comments
 (0)