Skip to content

Commit

Permalink
fix(VBreadcrumbs): v-for key error when two items have identical texts (
Browse files Browse the repository at this point in the history
#6642)

* fix(VBreadcrumbs): v-for key error when two items have identical texts

closes #5454

* test(VBreadcrumbs): remove .only from test
  • Loading branch information
nekosaur authored and johnleider committed Mar 3, 2019
1 parent 67b73b9 commit 2146ca8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/vuetify/src/components/VBreadcrumbs/VBreadcrumbs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,15 @@ export default mixins(
genItems () {
const items = []
const hasSlot = !!this.$scopedSlots.item
const keys = []

for (let i = 0; i < this.items.length; i++) {
const item = this.items[i]

keys.push(item.text)

This comment has been minimized.

Copy link
@bepsvpt

bepsvpt Mar 25, 2019

Contributor

When pushing item.text before hasSlot and there is no text property, it will result in exception.

(We use slot to render custom template and text property will not always exist.)

This comment has been minimized.

Copy link
@nekosaur

nekosaur Mar 25, 2019

Author Member

Please create an issue


if (hasSlot) items.push(this.$scopedSlots.item!({ item }))
else items.push(this.$createElement(VBreadcrumbsItem, { key: item.text, props: item }, [item.text]))
else items.push(this.$createElement(VBreadcrumbsItem, { key: keys.join('.'), props: item }, [item.text]))

if (i < this.items.length - 1) items.push(this.genDivider())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ test('VBreadcrumbs.js', ({ mount, compileToFunctions }) => {
expect(wrapper.html()).toMatchSnapshot()
})

it('should not complain about identical keys', () => {
const { render } = compileToFunctions(`
<v-breadcrumbs :items="items"></v-breadcrumbs>
`)

const component = Vue.component('test', {
components: {
VBreadcrumbs, VBreadcrumbsItem
},
data: () => ({
items: [
{ text: 'a' },
{ text: 'a' }
]
}),
render
})
const wrapper = mount(component)

expect(`Duplicate keys detected: 'a'`).not.toHaveBeenWarned()
})

it('should use slot to render items if present', () => {
const { render } = compileToFunctions(`
<v-breadcrumbs :items="items">
Expand Down

0 comments on commit 2146ca8

Please sign in to comment.