Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

#393 - Feature: pass in the page when emitting the page change event #394

Merged
merged 3 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/src/components/pagination.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Scroll to the top of the page after a page was changed:
<script>
export default {
methods: {
onPageChange() {
onPageChange(page) {
window.scrollTo(0,0);
}
}
Expand Down Expand Up @@ -76,6 +76,6 @@ Scroll to the top of the page after a page was changed:

## Events

| Event name | Description |
|-------------|----------------------------------------------------------------------------------------------|
| page-change | Triggered right after a page was changed due to an action taken on the pagination component. |
| Event name | Variables | Description |
|-------------|------------|----------------------------------------------------------------------------------------------|
| page-change | page | Triggered right after a page was changed due to an action taken on the pagination component. |
2 changes: 1 addition & 1 deletion src/components/Pagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default {
return;
}
this.searchStore.page = p;
this.$emit('page-change');
this.$emit('page-change', p);
},
goToFirstPage() {
this.goToPage(1);
Expand Down
6 changes: 5 additions & 1 deletion src/components/__tests__/pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ test('it should be hidden if there are no results in the current context', () =>
expect(vm.$el.outerHTML).toMatchSnapshot();
});

test('it should emit a "page-change" event when page changes', () => {
test('it should emit a "page-change" event when page changes and pass in the page variable', () => {
const searchStore = {
page: 1,
totalPages: 20,
Expand All @@ -115,4 +115,8 @@ test('it should emit a "page-change" event when page changes', () => {
.getElementsByTagName('a')[0]
.click();
expect(onPageChange).toHaveBeenCalledTimes(1);

const page = searchStore.page;
expect(onPageChange).toHaveBeenCalledWith(page);
expect(page).toBe(2);
});