Skip to content

Commit 18ee7bf

Browse files
authored
Merge pull request #166 from lombervid/fix-current
Prevent current page button to emit event
2 parents dbc21a3 + 422ce7b commit 18ee7bf

File tree

5 files changed

+60
-2
lines changed

5 files changed

+60
-2
lines changed

src/RenderlessPagination.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export default {
115115
this.selectPage((this.currentPage + 1));
116116
},
117117
selectPage (page) {
118-
if (page === '...') {
118+
if (page === '...' || page === this.currentPage) {
119119
return;
120120
}
121121

src/TailwindPagination.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
v-for="(page, key) in slotProps.computed.pageRange"
4040
:key="key"
4141
v-on="slotProps.pageButtonEvents(page)"
42+
:disabled="page === slotProps.computed.currentPage"
4243
>
4344
{{ page }}
4445
</button>
@@ -70,7 +71,7 @@ export default {
7071
compatConfig: {
7172
MODE: 3
7273
},
73-
74+
7475
inheritAttrs: false,
7576
7677
emits: ['pagination-change-page'],

tests/unit/Bootstrap4Pagination.spec.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ test('has correct DOM structure when on page 2', function () {
146146
});
147147

148148
test('emits correct event', function () {
149+
exampleData.current_page = 1;
149150
const wrapper = mount(Bootstrap4Pagination, {
150151
props: {
151152
data: exampleData,
@@ -159,6 +160,20 @@ test('emits correct event', function () {
159160
expect(event[0]).toEqual([2]);
160161
});
161162

163+
test('does not emit event on current page', function () {
164+
exampleData.current_page = 1;
165+
const wrapper = mount(Bootstrap4Pagination, {
166+
props: {
167+
data: exampleData,
168+
},
169+
});
170+
171+
wrapper.findAll('li').at(1).find('a').trigger('click');
172+
173+
const event = wrapper.emitted('pagination-change-page');
174+
expect(event).toBeUndefined();
175+
});
176+
162177
test('has correct DOM structure when using slots', function () {
163178
const wrapper = mount(Bootstrap4Pagination, {
164179
props: { data: exampleData },

tests/unit/Bootstrap5Pagination.spec.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ test('has correct DOM structure when on page 2', function () {
146146
});
147147

148148
test('emits correct event', function () {
149+
exampleData.current_page = 1;
149150
const wrapper = mount(Bootstrap5Pagination, {
150151
props: {
151152
data: exampleData,
@@ -159,6 +160,20 @@ test('emits correct event', function () {
159160
expect(event[0]).toEqual([2]);
160161
});
161162

163+
test('does not emit event on current page', function () {
164+
exampleData.current_page = 1;
165+
const wrapper = mount(Bootstrap5Pagination, {
166+
props: {
167+
data: exampleData,
168+
},
169+
});
170+
171+
wrapper.findAll('li').at(1).find('a').trigger('click');
172+
173+
const event = wrapper.emitted('pagination-change-page');
174+
expect(event).toBeUndefined();
175+
});
176+
162177
test('has correct DOM structure when using slots', function () {
163178
const wrapper = mount(Bootstrap5Pagination, {
164179
props: { data: exampleData },

tests/unit/TailwindPagination.spec.mjs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ test('has correct DOM structure when on page 2', function () {
118118
});
119119

120120
test('emits correct event', function () {
121+
exampleData.current_page = 1;
121122
const wrapper = mount(TailwindPagination, {
122123
props: {
123124
data: exampleData,
@@ -131,6 +132,32 @@ test('emits correct event', function () {
131132
expect(event[0]).toEqual([2]);
132133
});
133134

135+
test('does not emit event on current page', function () {
136+
exampleData.current_page = 1;
137+
const wrapper = mount(TailwindPagination, {
138+
props: {
139+
data: exampleData,
140+
},
141+
});
142+
143+
wrapper.findAll('button').at(1).trigger('click');
144+
145+
const event = wrapper.emitted('pagination-change-page');
146+
expect(event).toBeUndefined();
147+
});
148+
149+
test('current page button is disabled', function () {
150+
exampleData.current_page = 1;
151+
const wrapper = mount(TailwindPagination, {
152+
props: {
153+
data: exampleData,
154+
},
155+
});
156+
157+
const button = wrapper.findAll('button').at(1);
158+
expect(button.attributes('disabled')).toBe('');
159+
});
160+
134161
test('has correct DOM structure when using slots', function () {
135162
const wrapper = mount(TailwindPagination, {
136163
props: { data: exampleData },

0 commit comments

Comments
 (0)