Skip to content

Commit e6a1710

Browse files
committed
fix(VTreeview): select trunk nodes on click when openOnClick=false
fixes #21599
1 parent 5d1ceab commit e6a1710

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

Lines changed: 12 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 } from 'vue'
11+
import { computed, reactive, ref, toRaw } from 'vue'
1212
import { genericComponent, propsFactory } from '@/util'
1313

1414
// Types
@@ -74,8 +74,14 @@ export const VTreeviewChildren = genericComponent<new <T extends InternalListIte
7474

7575
setup (props, { slots }) {
7676
const isLoading = reactive(new Set<unknown>())
77+
const activatorItems = ref<VTreeviewItem[]>([])
7778

78-
const isClickOnOpen = computed(() => !props.disabled && (props.openOnClick != null ? props.openOnClick : props.selectable))
79+
const isClickOnOpen = computed(() => (
80+
!props.disabled && (
81+
props.openOnClick != null
82+
? props.openOnClick
83+
: props.selectable
84+
)))
7985

8086
async function checkChildren (item: InternalListItem) {
8187
try {
@@ -161,11 +167,14 @@ export const VTreeviewChildren = genericComponent<new <T extends InternalListIte
161167
...activatorProps,
162168
value: itemProps?.value,
163169
onToggleExpand: [() => checkChildren(item), activatorProps.onClick] as any,
164-
onClick: isClickOnOpen.value ? [() => checkChildren(item), activatorProps.onClick] as any : undefined,
170+
onClick: isClickOnOpen.value
171+
? [() => checkChildren(item), activatorProps.onClick] as any
172+
: () => selectItem(activatorItems.value[index]?.select, !activatorItems.value[index]?.isSelected),
165173
}
166174

167175
return (
168176
<VTreeviewItem
177+
ref={ el => activatorItems.value[index] = el as VTreeviewItem }
169178
{ ...listItemProps }
170179
value={ props.returnObject ? item.raw : itemProps.value }
171180
loading={ loading }

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { makeVListItemProps, VListItem } from '@/components/VList/VListItem'
88
import { VProgressCircular } from '@/components/VProgressCircular'
99

1010
// Composables
11+
import { forwardRefs } from '@/composables/forwardRefs'
1112
import { IconValue } from '@/composables/icons'
1213

1314
// Utilities
@@ -124,7 +125,7 @@ export const VTreeviewItem = genericComponent<VListItemSlots>()({
124125
)
125126
})
126127

127-
return {}
128+
return forwardRefs({}, vListItemRef)
128129
},
129130
})
130131

0 commit comments

Comments
 (0)