diff --git a/packages/vuetify/src/labs/VTreeview/VTreeviewItem.tsx b/packages/vuetify/src/labs/VTreeview/VTreeviewItem.tsx index c3a33eee6ba..b6968afa059 100644 --- a/packages/vuetify/src/labs/VTreeview/VTreeviewItem.tsx +++ b/packages/vuetify/src/labs/VTreeview/VTreeviewItem.tsx @@ -47,13 +47,8 @@ export const VTreeviewItem = genericComponent()({ (props.link || link.isClickable.value || (props.value != null && !!vListItemRef.value?.list) || isActivatableGroupActivator.value) ) - function activateItem (e: MouseEvent | KeyboardEvent) { - if ( - !isClickable.value || - (!isActivatableGroupActivator.value && vListItemRef.value?.isGroupActivator) - ) return - - if (vListItemRef.value?.root.activatable.value) { + function activateGroupActivator (e: MouseEvent | KeyboardEvent) { + if (isClickable.value && isActivatableGroupActivator.value) { vListItemRef.value?.activate(!vListItemRef.value?.isActivated, e) } } @@ -78,7 +73,7 @@ export const VTreeviewItem = genericComponent()({ props.class, ]} ripple={ false } - onClick={ props.onClick ?? activateItem } + onClick={ props.onClick ?? activateGroupActivator } > {{ ...slots, diff --git a/packages/vuetify/src/labs/VTreeview/__tests__/VTreeview.spec.browser.tsx b/packages/vuetify/src/labs/VTreeview/__tests__/VTreeview.spec.browser.tsx index 0e9ef6b7ec1..ec74dfca194 100644 --- a/packages/vuetify/src/labs/VTreeview/__tests__/VTreeview.spec.browser.tsx +++ b/packages/vuetify/src/labs/VTreeview/__tests__/VTreeview.spec.browser.tsx @@ -156,6 +156,27 @@ describe.each([ await userEvent.click(screen.getByText(/Nekosaur/)) expect(activated.value).toStrictEqual([203]) }) + + // https://github.com/vuetifyjs/vuetify/issues/20665 + it('should emit only once', async () => { + const onActivated = vi.fn() + render(() => ( + + )) + + await userEvent.click(screen.getByText(/John/)) + expect(onActivated).toHaveBeenCalledOnce() + + await userEvent.click(screen.getByText(/Human Resources/)) + expect(onActivated).toHaveBeenCalledTimes(2) + }) }) describe('select', () => {