Skip to content

Commit

Permalink
fix(VDataTable): handle items-per-page-options with objects (#8819)
Browse files Browse the repository at this point in the history
* fix(VDataTable): handle items-per-page-options with objects

closes #8817

* fix: cleaner code
  • Loading branch information
nekosaur authored and johnleider committed Sep 24, 2019
1 parent 8ba982d commit 81703af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/vuetify/src/components/VDataTable/VDataTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,14 @@ export default VDataIterator.extend({
},
computedItemsPerPage (): number {
const itemsPerPage = this.options && this.options.itemsPerPage ? this.options.itemsPerPage : this.itemsPerPage
if (this.sanitizedFooterProps.itemsPerPageOptions && !this.sanitizedFooterProps.itemsPerPageOptions.includes(itemsPerPage)) {
const firstOption = this.sanitizedFooterProps.itemsPerPageOptions[0]
const { itemsPerPageOptions } = this.sanitizedFooterProps
if (
itemsPerPageOptions &&
!itemsPerPageOptions.find((item: number | { value: number }) => {
return typeof item === 'number' ? item === itemsPerPage : item.value === itemsPerPage
})
) {
const firstOption = itemsPerPageOptions[0]
return typeof firstOption === 'object' ? firstOption.value : firstOption
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ describe('VDataTable.ts', () => {

expect(wrapper.html()).toMatchSnapshot()
})

// https://github.com/vuetifyjs/vuetify/issues/8184
it('should default to first option in itemsPerPageOptions if it does not include itemsPerPage', async () => {
const itemsPerPage = jest.fn()
Expand All @@ -458,4 +459,24 @@ describe('VDataTable.ts', () => {
itemsPerPage: 5,
}))
})

// https://github.com/vuetifyjs/vuetify/issues/8817
it('should handle object when checking if it should default to first option in itemsPerPageOptions', async () => {
const itemsPerPage = jest.fn()
const wrapper = mountFunction({
propsData: {
headers: testHeaders,
items: testItems,
itemsPerPage: -1,
footerProps: {
itemsPerPageOptions: [5, 6, { text: 'All', value: -1 }],
},
},
listeners: {
'update:items-per-page': itemsPerPage,
},
})

expect(itemsPerPage).toHaveBeenCalledWith(-1)
})
})

0 comments on commit 81703af

Please sign in to comment.