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

fix(VTreeview): search doesn't work with return-object #20508

Merged
merged 3 commits into from
Sep 22, 2024
Merged
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
6 changes: 5 additions & 1 deletion packages/vuetify/src/labs/VTreeview/VTreeview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ export const VTreeview = genericComponent<new <T>(
const getPath = vListRef.value?.getPath
if (!getPath) return null
return new Set(filteredItems.value.flatMap(item => {
return [...getPath(item.props.value), ...getChildren(item.props.value)]
const itemVal = props.returnObject ? item.raw : item.props.value
return [
...getPath(itemVal),
...getChildren(itemVal),
].map(toRaw)
}))
})

Expand Down
103 changes: 102 additions & 1 deletion packages/vuetify/src/labs/VTreeview/__tests__/VTreeview.spec.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

// Components
import { VTreeview } from '../VTreeview'
import { VTextField } from '@/components/VTextField'

// Utilities
import { ref } from 'vue'
import { ref, shallowRef } from 'vue'

function compareItemObject (a: any, b: any) {
return a.id - b.id
Expand Down Expand Up @@ -849,6 +850,106 @@ describe('VTreeview', () => {
})
})
})
describe('search', () => {
// https://github.com/vuetifyjs/vuetify/issues/20488
it('should filter items based on the search text and return the correct result', () => {
const items = ref([
{
id: 1,
title: 'Vuetify Human Resources',
children: [
{
id: 2,
title: 'Core team',
children: [
{
id: 201,
title: 'John',
},
{
id: 202,
title: 'Kael',
},
{
id: 203,
title: 'Nekosaur',
},
{
id: 204,
title: 'Jacek',
},
{
id: 205,
title: 'Andrew',
},
],
},
{
id: 3,
title: 'Administrators',
children: [
{
id: 301,
title: 'Mike',
},
{
id: 302,
title: 'Hunt',
},
],
},
{
id: 4,
title: 'Contributors',
children: [
{
id: 401,
title: 'Phlow',
},
{
id: 402,
title: 'Brandon',
},
{
id: 403,
title: 'Sean',
},
],
},
],
},
])
const search = shallowRef('')

function filterFn (value: string, search: string) {
return value.toLowerCase().includes(search.toLowerCase())
}
cy.mount(() => (
<>
<VTextField v-model={ search.value } />
<VTreeview
customFilter={ filterFn }
search={ search.value }
items={ items.value }
item-title="title"
item-value="id"
open-all
return-object
/>
</>
))
.get('.v-text-field input')
.type('j')
.get('.v-treeview-item').eq(0).should('be.visible') // { id: 1, title: 'Vuetify Human Resources' }
.get('.v-treeview-item').eq(1).should('be.visible') // { id: 2, title: 'Core team' }
.get('.v-treeview-item').eq(2).should('be.visible') // { id: 201, title: 'John' }
.get('.v-treeview-item').eq(3).should('not.be.visible')
.get('.v-treeview-item').eq(4).should('not.be.visible')
.get('.v-treeview-item').eq(5).should('be.visible') // { id: 204, title: 'Jacek' }
.get('.v-treeview-item').eq(9).should('not.be.visible')
.get('.v-treeview-item').eq(13).should('not.be.visible')
})
})
})

it('should have all items visible when open-all is applied', () => {
Expand Down