Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(VDataTable): selection duplication #18908

Merged
merged 2 commits into from
Apr 8, 2024
Merged
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
19 changes: 10 additions & 9 deletions packages/vuetify/src/components/VDataTable/composables/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useProxiedModel } from '@/composables/proxiedModel'

// Utilities
import { computed, inject, provide } from 'vue'
import { computed, inject, provide, toRaw, toRef } from 'vue'
import { deepEqual, propsFactory, wrapInArray } from '@/util'

// Types
Expand Down Expand Up @@ -45,7 +45,7 @@ const singleSelectStrategy: DataTableSelectStrategy = {
showSelectAll: false,
allSelected: () => [],
select: ({ items, value }) => {
return new Set(value ? [items[0]?.value] : [])
return new Set(value ? [toRaw(items[0]?.value)] : [])
},
selectAll: ({ selected }) => selected,
}
Expand All @@ -55,8 +55,8 @@ const pageSelectStrategy: DataTableSelectStrategy = {
allSelected: ({ currentPage }) => currentPage,
select: ({ items, value, selected }) => {
for (const item of items) {
if (value) selected.add(item.value)
else selected.delete(item.value)
if (value) selected.add(toRaw(item.value))
else selected.delete(toRaw(item.value))
}

return selected
Expand All @@ -69,8 +69,8 @@ const allSelectStrategy: DataTableSelectStrategy = {
allSelected: ({ allItems }) => allItems,
select: ({ items, value, selected }) => {
for (const item of items) {
if (value) selected.add(item.value)
else selected.delete(item.value)
if (value) selected.add(toRaw(item.value))
else selected.delete(toRaw(item.value))
}

return selected
Expand Down Expand Up @@ -123,11 +123,11 @@ export function provideSelection (
})

function isSelected (items: SelectableItem | SelectableItem[]) {
return wrapInArray(items).every(item => selected.value.has(item.value))
return wrapInArray(items).every(item => selected.value.has(toRaw(item.value)))
}

function isSomeSelected (items: SelectableItem | SelectableItem[]) {
return wrapInArray(items).some(item => selected.value.has(item.value))
return wrapInArray(items).some(item => selected.value.has(toRaw(item.value)))
}

function select (items: SelectableItem[], value: boolean) {
Expand All @@ -141,7 +141,8 @@ export function provideSelection (
}

function toggleSelect (item: SelectableItem) {
select([item], !isSelected([item]))
const newItem = toRef(item)
select([newItem.value], !isSelected([newItem.value]))
}

function selectAll (value: boolean) {
Expand Down
Loading