Skip to content

Commit 6c49868

Browse files
committed
refactor: CListGroup and CListGroupItem changes
- add horizontal prop to CListGroup, - add default role 'list-items' to CListGroup, - change default tags to ul for CListGroup, and li for CListGroupItem
1 parent c4664c1 commit 6c49868

File tree

6 files changed

+29
-12
lines changed

6 files changed

+29
-12
lines changed

src/components/ListGroup/CListGroup.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@ export default {
77
props: {
88
tag: {
99
type: String,
10-
default: 'div'
10+
default: 'ul'
1111
},
1212
flush: Boolean,
13+
horizontal: [Boolean, String]
1314
},
1415
render (h, { props, data, children }) {
16+
const hor = props.horizontal
17+
const horizontalClassSuffix = typeof hor === 'string' ? `-${hor}` : ''
1518
const componentData = {
1619
staticClass: 'list-group',
17-
class: { 'list-group-flush': props.flush }
20+
class: {
21+
'list-group-flush': !hor && props.flush,
22+
[`list-group-horizontal${horizontalClassSuffix}`]: hor,
23+
},
24+
attrs: {
25+
role: data.attrs ? data.attrs.role || 'list-items' : 'list-items'
26+
}
1827
}
1928
return h(props.tag, mergeData(data, componentData), children)
2029
}

src/components/ListGroup/CListGroupItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const props = Object.assign(
77
{
88
tag: {
99
type: String,
10-
default: 'div'
10+
default: 'li'
1111
},
1212
action: Boolean,
1313
variant: String

src/components/ListGroup/tests/CListGroup.spec.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { mount } from '@vue/test-utils'
22
import Component from '../CListGroup'
33

44
const ComponentName = 'CListGroup'
5-
const defaultWrapper = mount(Component)
5+
const wrapper = mount(Component, {
6+
propsData: {
7+
horizontal: 'sm'
8+
}
9+
})
10+
611
const customWrapper = mount(Component, {
712
propsData: {
813
flush: true
@@ -17,9 +22,9 @@ describe(ComponentName, () => {
1722
expect(Component.name).toMatch(ComponentName)
1823
})
1924
it('renders correctly', () => {
20-
expect(defaultWrapper.element).toMatchSnapshot()
25+
expect(wrapper.element).toMatchSnapshot()
2126
})
22-
it('renders correctly', () => {
27+
it('renders correctly with flush option', () => {
2328
expect(customWrapper.element).toMatchSnapshot()
2429
})
2530
})
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`CListGroup renders correctly 1`] = `
4-
<div
5-
class="list-group"
4+
<ul
5+
class="list-group list-group-horizontal-sm"
6+
role="list-items"
67
/>
78
`;
89

9-
exports[`CListGroup renders correctly 2`] = `
10-
<div
10+
exports[`CListGroup renders correctly with flush option 1`] = `
11+
<ul
1112
class="list-group list-group-flush"
13+
role="list-items"
1214
>
1315
<template>
1416
CListGroup content
1517
</template>
16-
</div>
18+
</ul>
1719
`;

src/components/ListGroup/tests/__snapshots__/CListGroupItem.spec.js.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`CListGroupItem renders correctly 1`] = `
4-
<div
4+
<li
55
class="list-group-item"
66
/>
77
`;

src/components/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ export declare class CLink extends Vue {
350350
export declare class CListGroup extends Vue {
351351
tag: string
352352
flush: boolean
353+
horizontal: [string, boolean]
353354
}
354355

355356
export declare class CListGroupitem extends CLink {

0 commit comments

Comments
 (0)