Skip to content

Commit d807367

Browse files
committed
fix(MdDivider): create divider as <li> tag when direct inside lists
1 parent 271f059 commit d807367

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/components/MdDivider/MdDivider.test.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Vue from 'vue'
12
import mountTemplate from 'test/utils/mountTemplate'
23
import MdDivider from './MdDivider.vue'
34

@@ -9,8 +10,30 @@ test('should render the divider', async () => {
910
})
1011

1112
test('should render the theme class', async () => {
12-
const template = '<md-divider md-theme="alt">Lorem ipsum</md-divider>'
13+
const template = '<md-divider md-theme="alt"></md-divider>'
1314
const wrapper = await mountTemplate(MdDivider, template)
1415

1516
expect(wrapper.hasClass('md-theme-alt')).toBe(true)
1617
})
18+
19+
test('should render a <li> tag when inside lists', async () => {
20+
Vue.component('MdList', {
21+
template: '<div><slot></slot></div>'
22+
})
23+
const template = `
24+
<md-list>
25+
<md-divider></md-divider>
26+
</md-list>`
27+
const wrapper = await mountTemplate(MdDivider, template)
28+
const divider = wrapper.find(MdDivider)[0]
29+
30+
expect(divider.vm.$el.tagName.toLowerCase()).toBe('li')
31+
})
32+
33+
test('should render a <hr> tag when inside any other element', async () => {
34+
const template = `<md-divider></md-divider>`
35+
const wrapper = await mountTemplate(MdDivider, template)
36+
const divider = wrapper.find(MdDivider)[0]
37+
38+
expect(divider.vm.$el.tagName.toLowerCase()).toBe('hr')
39+
})

src/components/MdDivider/MdDivider.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
<template>
2-
<hr class="md-divider" :class="[$mdActiveTheme]">
2+
<li class="md-divider" :class="[$mdActiveTheme]" v-if="insideList"></li>
3+
<hr class="md-divider" :class="[$mdActiveTheme]" v-else>
34
</template>
45

56
<script>
67
import MdComponent from 'core/MdComponent'
78
89
export default new MdComponent({
9-
name: 'MdDivider'
10+
name: 'MdDivider',
11+
computed: {
12+
insideList () {
13+
return this.$parent.$options._componentTag === 'md-list'
14+
}
15+
}
1016
})
1117
</script>
1218

0 commit comments

Comments
 (0)