Skip to content

Commit a2fccb4

Browse files
Florent CHAUVEAUjohnleider
Florent CHAUVEAU
authored andcommitted
fix(DataIterable): do not update selection if totalItems is set (#7396)
fixes #6472
1 parent a03714b commit a2fccb4

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

packages/vuetify/src/mixins/data-iterable.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,14 @@ export default {
231231
if (this.pageStart >= this.itemsLength) {
232232
this.resetPagination()
233233
}
234-
const newItemKeys = new Set(this.items.map(item => getObjectValueByPath(item, this.itemKey)))
235-
const selection = this.value.filter(item => newItemKeys.has(getObjectValueByPath(item, this.itemKey)))
236234

237-
if (selection.length !== this.value.length) {
238-
this.$emit('input', selection)
235+
if (this.totalItems === null) {
236+
const newItemKeys = new Set(this.items.map(item => getObjectValueByPath(item, this.itemKey)))
237+
const selection = this.value.filter(item => newItemKeys.has(getObjectValueByPath(item, this.itemKey)))
238+
239+
if (selection.length !== this.value.length) {
240+
this.$emit('input', selection)
241+
}
239242
}
240243
},
241244
search () {

packages/vuetify/test/unit/mixins/data-iterable.spec.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,32 @@ test('data-iterable.js', ({ mount }) => {
123123
expect(callCount).toBe(2)
124124
expect(selectionChanged).toBeCalledWith([])
125125
})
126-
})
126+
127+
it('should not update selection if totalItems is set', async () => {
128+
const items = [{ id: 'foo' }, { id: 'bar' }]
129+
let value = []
130+
131+
const wrapper = dataIterableCmp(value, items)
132+
133+
let callCount = 0
134+
const selectionChanged = jest.fn()
135+
// Emulate v-model behaviour
136+
wrapper.vm.$on('input', function (newValue) {
137+
callCount += 1
138+
value = newValue
139+
selectionChanged.apply(this, arguments)
140+
})
141+
142+
wrapper.find('.select-me')[0].trigger('click')
143+
144+
expect(callCount).toBe(1)
145+
expect(selectionChanged).toBeCalledWith([items[0]])
146+
147+
// because totalItems is set,
148+
// the selection is not going to be updated
149+
wrapper.setProps({ value, items: [items[1]], totalItems: 42 })
150+
151+
expect(callCount).toBe(1)
152+
expect(selectionChanged).toBeCalledWith([items[0]])
153+
})
154+
})

0 commit comments

Comments
 (0)