Skip to content

Commit

Permalink
Merge pull request #166 from lombervid/fix-current
Browse files Browse the repository at this point in the history
Prevent current page button to emit event
  • Loading branch information
gilbitron authored Aug 7, 2023
2 parents dbc21a3 + 422ce7b commit 18ee7bf
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/RenderlessPagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export default {
this.selectPage((this.currentPage + 1));
},
selectPage (page) {
if (page === '...') {
if (page === '...' || page === this.currentPage) {
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/TailwindPagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
v-for="(page, key) in slotProps.computed.pageRange"
:key="key"
v-on="slotProps.pageButtonEvents(page)"
:disabled="page === slotProps.computed.currentPage"
>
{{ page }}
</button>
Expand Down Expand Up @@ -70,7 +71,7 @@ export default {
compatConfig: {
MODE: 3
},
inheritAttrs: false,
emits: ['pagination-change-page'],
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/Bootstrap4Pagination.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ test('has correct DOM structure when on page 2', function () {
});

test('emits correct event', function () {
exampleData.current_page = 1;
const wrapper = mount(Bootstrap4Pagination, {
props: {
data: exampleData,
Expand All @@ -159,6 +160,20 @@ test('emits correct event', function () {
expect(event[0]).toEqual([2]);
});

test('does not emit event on current page', function () {
exampleData.current_page = 1;
const wrapper = mount(Bootstrap4Pagination, {
props: {
data: exampleData,
},
});

wrapper.findAll('li').at(1).find('a').trigger('click');

const event = wrapper.emitted('pagination-change-page');
expect(event).toBeUndefined();
});

test('has correct DOM structure when using slots', function () {
const wrapper = mount(Bootstrap4Pagination, {
props: { data: exampleData },
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/Bootstrap5Pagination.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ test('has correct DOM structure when on page 2', function () {
});

test('emits correct event', function () {
exampleData.current_page = 1;
const wrapper = mount(Bootstrap5Pagination, {
props: {
data: exampleData,
Expand All @@ -159,6 +160,20 @@ test('emits correct event', function () {
expect(event[0]).toEqual([2]);
});

test('does not emit event on current page', function () {
exampleData.current_page = 1;
const wrapper = mount(Bootstrap5Pagination, {
props: {
data: exampleData,
},
});

wrapper.findAll('li').at(1).find('a').trigger('click');

const event = wrapper.emitted('pagination-change-page');
expect(event).toBeUndefined();
});

test('has correct DOM structure when using slots', function () {
const wrapper = mount(Bootstrap5Pagination, {
props: { data: exampleData },
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/TailwindPagination.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ test('has correct DOM structure when on page 2', function () {
});

test('emits correct event', function () {
exampleData.current_page = 1;
const wrapper = mount(TailwindPagination, {
props: {
data: exampleData,
Expand All @@ -131,6 +132,32 @@ test('emits correct event', function () {
expect(event[0]).toEqual([2]);
});

test('does not emit event on current page', function () {
exampleData.current_page = 1;
const wrapper = mount(TailwindPagination, {
props: {
data: exampleData,
},
});

wrapper.findAll('button').at(1).trigger('click');

const event = wrapper.emitted('pagination-change-page');
expect(event).toBeUndefined();
});

test('current page button is disabled', function () {
exampleData.current_page = 1;
const wrapper = mount(TailwindPagination, {
props: {
data: exampleData,
},
});

const button = wrapper.findAll('button').at(1);
expect(button.attributes('disabled')).toBe('');
});

test('has correct DOM structure when using slots', function () {
const wrapper = mount(TailwindPagination, {
props: { data: exampleData },
Expand Down

1 comment on commit 18ee7bf

@vercel
Copy link

@vercel vercel bot commented on 18ee7bf Aug 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.