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

feat(VTreeview): add slot to replace expand toggle btn #21018

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions packages/vuetify/src/labs/VTreeview/VTreeviewChildren.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export type VTreeviewChildrenSlots<T> = {
item: T
internalItem: InternalListItem<T>
}
toggle: {
props: { onClick?: (e: MouseEvent) => void }
}
}

export const makeVTreeviewChildrenProps = propsFactory({
Expand Down Expand Up @@ -93,6 +96,7 @@ export const VTreeviewChildren = genericComponent<new <T extends InternalListIte
const { children, props: itemProps } = item
const loading = isLoading.has(item.value)
const slotsWithItem = {
toggle: slots.toggle ? slotProps => slots.toggle?.(slotProps) : undefined,
prepend: slotProps => (
<>
{ props.selectable && (!children || (children && !['leaf', 'single-leaf'].includes(props.selectStrategy as string))) && (
Expand Down
77 changes: 57 additions & 20 deletions packages/vuetify/src/labs/VTreeview/VTreeviewItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import './VTreeviewItem.sass'

// Components
import { VBtn } from '@/components/VBtn'
import { VDefaultsProvider } from '@/components/VDefaultsProvider'
import { VListItemAction } from '@/components/VList'
import { makeVListItemProps, VListItem } from '@/components/VList/VListItem'
import { VProgressCircular } from '@/components/VProgressCircular'
Expand All @@ -26,7 +27,13 @@ export const makeVTreeviewItemProps = propsFactory({
...makeVListItemProps({ slim: true }),
}, 'VTreeviewItem')

export const VTreeviewItem = genericComponent<VListItemSlots>()({
export type VTreeviewItemSlots = VListItemSlots & {
toggle: {
props: { onClick?: (e: MouseEvent) => void }
}
}

export const VTreeviewItem = genericComponent<VTreeviewItemSlots>()({
name: 'VTreeviewItem',

props: makeVTreeviewItemProps(),
Expand All @@ -51,6 +58,12 @@ export const VTreeviewItem = genericComponent<VListItemSlots>()({
)
const isFiltered = computed(() => visibleIds.value && !visibleIds.value.has(toRaw(vListItemRef.value?.id)))

const toggleProps = computed(() => ({
props: {
onClick: props.onToggleExpand,
},
}))

function activateGroupActivator (e: MouseEvent | KeyboardEvent) {
if (isClickable.value && isActivatableGroupActivator.value) {
vListItemRef.value?.activate(!vListItemRef.value?.isActivated, e)
Expand Down Expand Up @@ -84,25 +97,49 @@ export const VTreeviewItem = genericComponent<VListItemSlots>()({
<>
<VListItemAction start={ false }>
{ props.toggleIcon ? (
<VBtn
density="compact"
icon={ props.toggleIcon }
loading={ props.loading }
variant="text"
onClick={ props.onToggleExpand }
>
{{
loader () {
return (
<VProgressCircular
indeterminate="disable-shrink"
size="20"
width="2"
/>
)
},
}}
</VBtn>
<>
{ !slots.toggle ? (
<VBtn
key="prepend-toggle"
density="compact"
icon={ props.toggleIcon }
loading={ props.loading }
variant="text"
onClick={ props.onToggleExpand }
>
{{
loader () {
return (
<VProgressCircular
indeterminate="disable-shrink"
size="20"
width="2"
/>
)
},
}}
</VBtn>
) : (
<VDefaultsProvider
key="prepend-defaults"
defaults={{
VBtn: {
density: 'compact',
icon: props.toggleIcon,
variant: 'text',
loading: props.loading,
},
VProgressCircular: {
indeterminate: 'disable-shrink',
size: 20,
width: 2,
},
}}
>
{ slots.toggle(toggleProps.value) }
</VDefaultsProvider>
)}
</>
) : (
<div class="v-treeview-item__level" />
)}
Expand Down