Skip to content

Commit cf865e0

Browse files
author
Dobromir Hristov
committed
refactor: do rename the ContentTableSection title to reduce polluting child .title classes.
1 parent 1c63f5d commit cf865e0

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

src/components/DocumentationTopic/ContentTableSection.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
<template>
1212
<div class="contenttable-section">
1313
<div class="section-title">
14-
<slot name="title">
14+
<slot name="title" :className="className">
1515
<LinkableHeading
1616
:level="3"
17-
class="title"
17+
:class="className"
1818
:anchor="anchorComputed"
1919
:register-on-this-page="false"
2020
>{{ title }}</LinkableHeading>
@@ -47,6 +47,7 @@ export default {
4747
},
4848
computed: {
4949
anchorComputed: ({ title, anchor }) => anchor || anchorize(title),
50+
className: () => 'contenttable-title',
5051
},
5152
};
5253
</script>
@@ -67,7 +68,7 @@ export default {
6768
}
6869
}
6970
70-
/deep/ .title {
71+
/deep/ .contenttable-title {
7172
@include font-styles(label);
7273
}
7374
@@ -86,7 +87,7 @@ export default {
8687
}
8788
}
8889
89-
/deep/ .title {
90+
/deep/ .contenttable-title {
9091
margin: 0 0 $contenttable-spacing-single-side 0;
9192
padding-bottom: 0.5rem;
9293
}

src/components/DocumentationTopic/TopicsTable.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
:title="section.title"
1717
:anchor="section.anchor"
1818
>
19-
<template v-if="wrapTitle" slot="title">
19+
<template v-if="wrapTitle" #title="{ className }">
2020
<LinkableHeading
2121
:level="3"
2222
:anchor="section.anchor"
23-
class="title"
23+
:class="className"
2424
:register-on-this-page="false"
2525
>
2626
<WordBreak>{{ section.title }}</WordBreak>

tests/unit/components/DocumentationTopic/ContentTableSection.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('ContentTableSection', () => {
3434
expect(title.exists()).toBe(true);
3535
expect(title.props('level')).toBe(3);
3636
expect(title.props('registerOnThisPage')).toBe(false);
37-
expect(title.classes('title')).toBe(true);
37+
expect(title.classes()).toContain('contenttable-title');
3838
expect(title.text()).toContain(propsData.title);
3939
});
4040

@@ -50,12 +50,12 @@ describe('ContentTableSection', () => {
5050
it('renders a slot for a title', () => {
5151
wrapper = shallowMount(ContentTableSection, {
5252
propsData,
53-
slots: {
54-
title: '<div class="title">Title Text</div>',
53+
scopedSlots: {
54+
title: '<div :class="props.className">Title Text</div>',
5555
},
5656
});
5757
const div = wrapper.find('.section-title');
58-
const title = div.find('.title');
58+
const title = div.find('.contenttable-title');
5959
expect(title.text()).toEqual('Title Text');
6060
});
6161

tests/unit/components/DocumentationTopic/TopicsTable.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ describe('TopicsTable', () => {
6666
wrapper = shallowMount(TopicsTable, {
6767
propsData,
6868
provide,
69+
stubs: {
70+
ContentTableSection,
71+
},
6972
});
7073
});
7174

@@ -173,5 +176,6 @@ describe('TopicsTable', () => {
173176
expect(linkableHeading.props('level')).toBe(3);
174177
expect(linkableHeading.props('registerOnThisPage')).toBe(false);
175178
expect(linkableHeading.attributes('anchor')).toBe(propsData.sections[0].anchor);
179+
expect(linkableHeading.classes()).toContain('contenttable-title');
176180
});
177181
});

0 commit comments

Comments
 (0)