Skip to content

Commit 431af5f

Browse files
committed
fix(VTreeview): prevent checkbox deselection when mandatory
fixes #21614
1 parent b4486f9 commit 431af5f

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

packages/vuetify/src/components/VTreeview/VTreeviewChildren.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { makeDensityProps } from '@/composables/density'
88
import { IconValue } from '@/composables/icons'
99

1010
// Utilities
11-
import { computed, reactive, toRaw, withModifiers } from 'vue'
11+
import { computed, reactive, toRaw } from 'vue'
1212
import { genericComponent, propsFactory } from '@/util'
1313

1414
// Types
@@ -92,7 +92,7 @@ export const VTreeviewChildren = genericComponent<new <T extends InternalListIte
9292

9393
function selectItem (select: (value: boolean) => void, isSelected: boolean) {
9494
if (props.selectable) {
95-
select(!isSelected)
95+
select(isSelected)
9696
}
9797
}
9898

@@ -124,7 +124,8 @@ export const VTreeviewChildren = genericComponent<new <T extends InternalListIte
124124
indeterminateIcon={ props.indeterminateIcon }
125125
falseIcon={ props.falseIcon }
126126
trueIcon={ props.trueIcon }
127-
onClick={ withModifiers(() => selectItem(slotProps.select, slotProps.isSelected), ['stop']) }
127+
onUpdate:modelValue={ v => selectItem(slotProps.select, v) }
128+
onClick={ (e: PointerEvent) => e.stopPropagation() }
128129
onKeydown={ (e: KeyboardEvent) => {
129130
if (!['Enter', 'Space'].includes(e.key)) return
130131
e.stopPropagation()

packages/vuetify/src/components/VTreeview/VTreeviewItem.tsx

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -91,27 +91,25 @@ export const VTreeviewItem = genericComponent<VListItemSlots>()({
9191
prepend: hasPrepend ? slotProps => {
9292
return (
9393
<>
94-
<VListItemAction start={ false }>
94+
<VListItemAction start>
9595
{ props.toggleIcon ? (
96-
<VBtn
97-
density="compact"
98-
icon={ props.toggleIcon }
99-
loading={ props.loading }
100-
variant="text"
101-
onClick={ onClickAction }
102-
>
103-
{{
104-
loader () {
105-
return (
106-
<VProgressCircular
107-
indeterminate="disable-shrink"
108-
size="20"
109-
width="2"
110-
/>
111-
)
112-
},
113-
}}
114-
</VBtn>
96+
<VBtn
97+
density="compact"
98+
icon={ props.toggleIcon }
99+
loading={ props.loading }
100+
variant="text"
101+
onClick={ onClickAction }
102+
>
103+
{{
104+
loader: () => (
105+
<VProgressCircular
106+
indeterminate="disable-shrink"
107+
size="20"
108+
width="2"
109+
/>
110+
),
111+
}}
112+
</VBtn>
115113
) : (
116114
<div class="v-treeview-item__level" />
117115
)}

0 commit comments

Comments
 (0)