Skip to content

Commit 248add9

Browse files
authored
fix(VDataTable): selection bug when using numbers as item-key (#14008)
closes #14006
1 parent 688f223 commit 248add9

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

packages/vuetify/src/components/VDataIterator/VDataIterator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ export default mixins(
201201

202202
const index = this.selectableItems.findIndex(x => getObjectValueByPath(x, this.itemKey) === key)
203203
if (this.lastEntry === -1) this.lastEntry = index
204-
else {
204+
else if (this.shiftKeyDown && !this.singleSelect && emit) {
205205
const lastEntryKey = getObjectValueByPath(this.selectableItems[this.lastEntry], this.itemKey)
206-
const lastEntryKeySelected = Object.keys(this.selection).includes(lastEntryKey.toString())
207-
if (this.shiftKeyDown && !this.singleSelect && emit) this.multipleSelect(lastEntryKeySelected, emit, selection, index)
206+
const lastEntryKeySelected = Object.keys(this.selection).includes(String(lastEntryKey))
207+
this.multipleSelect(lastEntryKeySelected, emit, selection, index)
208208
}
209209
this.lastEntry = index
210210

packages/vuetify/src/components/VDataTable/__tests__/VDataTable.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,4 +1070,38 @@ describe('VDataTable.ts', () => {
10701070
await wrapper.vm.$nextTick()
10711071
expect(wrapper.vm.internalCurrentItems).toHaveLength(1)
10721072
})
1073+
1074+
// https://github.com/vuetifyjs/vuetify/issues/14006
1075+
it('should allow selection on second page when using numbers as item key', async () => {
1076+
const input = jest.fn()
1077+
const items = testItems.map((item, index) => ({ ...item, name: index + 1 })).slice(0, 8)
1078+
const wrapper = mountFunction({
1079+
propsData: {
1080+
items,
1081+
itemKey: 'name',
1082+
itemsPerPage: 5,
1083+
showSelect: true,
1084+
headers: testHeaders,
1085+
mobileBreakpoint: 0,
1086+
},
1087+
listeners: {
1088+
input,
1089+
},
1090+
})
1091+
1092+
let checkbox = wrapper.findAll('td > .v-data-table__checkbox').at(4)
1093+
1094+
checkbox.trigger('click')
1095+
await wrapper.vm.$nextTick()
1096+
1097+
wrapper.setProps({ page: 2 })
1098+
await wrapper.vm.$nextTick()
1099+
1100+
checkbox = wrapper.findAll('td > .v-data-table__checkbox').at(0)
1101+
1102+
checkbox.trigger('click')
1103+
await wrapper.vm.$nextTick()
1104+
1105+
expect(input).toHaveBeenCalledWith([items[4], items[5]])
1106+
})
10731107
})

0 commit comments

Comments
 (0)