Skip to content

fix(nested): prevent parent node activate firing for singleLeaf #20951

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

Merged
merged 5 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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: 2 additions & 2 deletions packages/vuetify/src/composables/nested/nested.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
leafSelectStrategy,
leafSingleSelectStrategy,
} from './selectStrategies'
import { consoleError, getCurrentInstance, getUid, propsFactory } from '@/util'
import { arrayDiff, consoleError, getCurrentInstance, getUid, propsFactory } from '@/util'

// Types
import type { InjectionKey, PropType, Ref } from 'vue'
Expand Down Expand Up @@ -309,7 +309,7 @@ export const useNested = (props: NestedProps) => {
event,
})

newActivated && (activated.value = newActivated)
newActivated && arrayDiff(activated.value, newActivated).length && (activated.value = newActivated)
},
children,
parents,
Expand Down
9 changes: 6 additions & 3 deletions packages/vuetify/src/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,14 @@ export function filterInputAttrs (attrs: Record<string, unknown>) {

/**
* Returns the set difference of B and A, i.e. the set of elements in B but not in A
* A and B can be sets, but the function always returns the result as an array.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KaelWD What do you think of this change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they're already sets .has should be faster than .includes

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored to use symmetricDifference instead

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*/
export function arrayDiff (a: any[], b: any[]): any[] {
export function arrayDiff (a: any[] | Set<any>, b: any[] | Set<any>): any[] {
const diff: any[] = []
for (let i = 0; i < b.length; i++) {
if (!a.includes(b[i])) diff.push(b[i])
const aArr: any[] = a instanceof Set ? Array.from(a) : a
const bArr: any[] = b instanceof Set ? Array.from(b) : b
for (let i = 0; i < bArr.length; i++) {
if (!aArr.includes(bArr[i])) diff.push(bArr[i])
}
return diff
}
Expand Down