Skip to content

Commit 1c85397

Browse files
committed
[r96943502] fix: address feedback
1 parent 958483c commit 1c85397

27 files changed

+108
-82
lines changed

src/components/ContentNode.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<script>
1212
import Aside from './ContentNode/Aside.vue';
1313
import CodeListing from './ContentNode/CodeListing.vue';
14-
import SectionTitle from './ContentNode/SectionTitle.vue';
14+
import LinkableHeading from './ContentNode/LinkableHeading.vue';
1515
import CodeVoice from './ContentNode/CodeVoice.vue';
1616
import DictionaryExample from './ContentNode/DictionaryExample.vue';
1717
import EndpointExample from './ContentNode/EndpointExample.vue';
@@ -25,7 +25,6 @@ import StrikeThrough from './ContentNode/StrikeThrough.vue';
2525
const BlockType = {
2626
aside: 'aside',
2727
codeListing: 'codeListing',
28-
sectionTitle: 'sectionTitle',
2928
endpointExample: 'endpointExample',
3029
heading: 'heading',
3130
orderedList: 'orderedList',
@@ -232,9 +231,9 @@ function renderNode(createElement, references) {
232231
case BlockType.heading: {
233232
const props = {
234233
anchor: node.anchor,
235-
tag: `h${node.level}`,
234+
level: Number(node.level),
236235
};
237-
return createElement(SectionTitle, { props }, node.text);
236+
return createElement(LinkableHeading, { props }, node.text);
238237
}
239238
case BlockType.orderedList:
240239
return createElement('ol', {

src/components/ContentNode/SectionTitle.vue renamed to src/components/ContentNode/LinkableHeading.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
<template>
1212
<component
13-
:id="!isTargetIDE ? id : null"
14-
:is="tag"
13+
:id="id"
14+
:is="`h${level}`"
1515
class="section-title"
1616
>
1717
<a
@@ -28,8 +28,10 @@
2828
<script>
2929
import scrollToElement from 'docc-render/mixins/scrollToElement';
3030
31+
const HeadingLevels = [1, 2, 3, 4, 5, 6];
32+
3133
export default {
32-
name: 'SectionTitle',
34+
name: 'LinkableHeading',
3335
mixins: [scrollToElement],
3436
data() {
3537
return {
@@ -41,9 +43,10 @@ export default {
4143
type: String,
4244
required: false,
4345
},
44-
tag: {
45-
type: String,
46-
default: () => 'h2',
46+
level: {
47+
type: Number,
48+
default: () => 2,
49+
validator: v => v in HeadingLevels,
4750
},
4851
},
4952
inject: {

src/components/DocumentationTopic/ContentTable.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
:title="title"
1616
>
1717
<div class="container">
18-
<SectionTitle class="title" :anchor="anchor">{{ title }}</SectionTitle>
18+
<LinkableHeading class="title" :anchor="anchor">{{ title }}</LinkableHeading>
1919
<slot />
2020
</div>
2121
</OnThisPageSection>
2222
</template>
2323

2424
<script>
25-
import SectionTitle from 'docc-render/components/ContentNode/SectionTitle.vue';
25+
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
2626
import OnThisPageSection from './OnThisPageSection.vue';
2727
2828
export default {
2929
name: 'ContentTable',
30-
components: { OnThisPageSection, SectionTitle },
30+
components: { OnThisPageSection, LinkableHeading },
3131
props: {
3232
anchor: {
3333
type: String,

src/components/DocumentationTopic/ContentTableSection.vue

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
<div class="contenttable-section">
1313
<div class="section-title">
1414
<slot name="title">
15-
<SectionTitle tag="h3" class="title" :anchor="anchor">{{ title }}</SectionTitle>
15+
<LinkableHeading
16+
:level="3"
17+
class="title"
18+
:anchor="anchorComputed"
19+
>{{ title }}</LinkableHeading>
1620
</slot>
1721
</div>
1822
<div class="section-content">
@@ -24,20 +28,24 @@
2428
</template>
2529

2630
<script>
27-
import SectionTitle from 'docc-render/components/ContentNode/SectionTitle.vue';
31+
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
2832
import { anchorize } from 'docc-render/utils/strings';
2933
3034
export default {
3135
name: 'ContentTableSection',
32-
components: { SectionTitle },
36+
components: { LinkableHeading },
3337
props: {
3438
title: {
3539
type: String,
3640
required: true,
3741
},
42+
anchor: {
43+
type: String,
44+
default: null,
45+
},
3846
},
3947
computed: {
40-
anchor: ({ title }) => anchorize(title),
48+
anchorComputed: ({ title, anchor }) => anchor || anchorize(title),
4149
},
4250
};
4351
</script>

src/components/DocumentationTopic/PrimaryContent/Declaration.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class="declaration"
1515
title="Declaration"
1616
>
17-
<SectionTitle anchor="declaration">Declaration</SectionTitle>
17+
<LinkableHeading anchor="declaration">Declaration</LinkableHeading>
1818
<template v-if="hasModifiedChanges">
1919
<DeclarationDiff
2020
:class="[changeClasses, multipleLinesClass]"
@@ -48,7 +48,7 @@
4848
<script>
4949
import ConditionalConstraints from 'docc-render/components/DocumentationTopic/ConditionalConstraints.vue';
5050
import OnThisPageSection from 'docc-render/components/DocumentationTopic/OnThisPageSection.vue';
51-
import SectionTitle from 'docc-render/components/ContentNode/SectionTitle.vue';
51+
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
5252
5353
import DeclarationGroup from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationGroup.vue';
5454
import DeclarationDiff
@@ -66,7 +66,7 @@ export default {
6666
DeclarationSourceLink,
6767
ConditionalConstraints,
6868
OnThisPageSection,
69-
SectionTitle,
69+
LinkableHeading,
7070
},
7171
constants: { ChangeTypes, multipleLinesClass },
7272
inject: ['identifier', 'store'],

src/components/DocumentationTopic/PrimaryContent/Parameters.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
class="parameters"
1515
title="Parameters"
1616
>
17-
<SectionTitle anchor="parameters">Parameters</SectionTitle>
17+
<LinkableHeading anchor="parameters">Parameters</LinkableHeading>
1818
<dl>
1919
<template v-for="param in parameters">
2020
<dt class="param-name" :key="`${param.name}:name`">
@@ -31,14 +31,14 @@
3131
<script>
3232
import ContentNode from 'docc-render/components/DocumentationTopic/ContentNode.vue';
3333
import OnThisPageSection from 'docc-render/components/DocumentationTopic/OnThisPageSection.vue';
34-
import SectionTitle from 'docc-render/components/ContentNode/SectionTitle.vue';
34+
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
3535
3636
export default {
3737
name: 'Parameters',
3838
components: {
3939
ContentNode,
4040
OnThisPageSection,
41-
SectionTitle,
41+
LinkableHeading,
4242
},
4343
props: {
4444
parameters: {

src/components/DocumentationTopic/PrimaryContent/PropertyTable.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<template>
1212
<OnThisPageSection :anchor="anchor" :title="title">
13-
<SectionTitle :anchor="anchor">{{ title }}</SectionTitle>
13+
<LinkableHeading :anchor="anchor">{{ title }}</LinkableHeading>
1414
<ParametersTable :parameters="properties" :changes="propertyChanges" class="property-table">
1515
<template slot="symbol" slot-scope="{ name, type, content, changes, deprecated }">
1616
<div class="property-name" :class="{ deprecated: deprecated }">
@@ -60,7 +60,7 @@
6060

6161
<script>
6262
import { anchorize } from 'docc-render/utils/strings';
63-
import SectionTitle from 'docc-render/components/ContentNode/SectionTitle.vue';
63+
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
6464
import WordBreak from 'docc-render/components/WordBreak.vue';
6565
import ContentNode from 'docc-render/components/DocumentationTopic/ContentNode.vue';
6666
@@ -84,7 +84,7 @@ export default {
8484
ContentNode,
8585
OnThisPageSection,
8686
ParametersTable,
87-
SectionTitle,
87+
LinkableHeading,
8888
},
8989
props: {
9090
title: {

src/components/DocumentationTopic/PrimaryContent/RestBody.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<template>
1212
<OnThisPageSection :anchor="anchor" :title="title">
13-
<SectionTitle :anchor="anchor">{{ title }}</SectionTitle>
13+
<LinkableHeading :anchor="anchor">{{ title }}</LinkableHeading>
1414
<ParametersTable :parameters="[bodyParam]" :changes="bodyChanges" keyBy="key">
1515
<template slot="symbol" slot-scope="{ type, content, changes, name }">
1616
<PossiblyChangedType
@@ -84,7 +84,7 @@
8484
import { anchorize } from 'docc-render/utils/strings';
8585
import ContentNode from 'docc-render/components/DocumentationTopic/ContentNode.vue';
8686
import OnThisPageSection from 'docc-render/components/DocumentationTopic/OnThisPageSection.vue';
87-
import SectionTitle from 'docc-render/components/ContentNode/SectionTitle.vue';
87+
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
8888
8989
import WordBreak from 'docc-render/components/WordBreak.vue';
9090
import apiChangesProvider from 'docc-render/mixins/apiChangesProvider';
@@ -108,7 +108,7 @@ export default {
108108
ContentNode,
109109
OnThisPageSection,
110110
ParametersTable,
111-
SectionTitle,
111+
LinkableHeading,
112112
},
113113
constants: { ChangesKey },
114114
props: {

src/components/DocumentationTopic/PrimaryContent/RestEndpoint.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
<template>
1212
<OnThisPageSection :anchor="anchor" :title="title">
13-
<SectionTitle :anchor="anchor">{{ title }}</SectionTitle>
13+
<LinkableHeading :anchor="anchor">{{ title }}</LinkableHeading>
1414
<DeclarationSource :tokens="tokens" />
1515
</OnThisPageSection>
1616
</template>
1717

1818
<script>
1919
import { anchorize } from 'docc-render/utils/strings';
2020
import OnThisPageSection from 'docc-render/components/DocumentationTopic/OnThisPageSection.vue';
21-
import SectionTitle from 'docc-render/components/ContentNode/SectionTitle.vue';
21+
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
2222
import DeclarationSource
2323
from 'docc-render/components/DocumentationTopic/PrimaryContent/DeclarationSource.vue';
2424
@@ -30,7 +30,7 @@ export default {
3030
components: {
3131
DeclarationSource,
3232
OnThisPageSection,
33-
SectionTitle,
33+
LinkableHeading,
3434
},
3535
props: {
3636
title: {

src/components/DocumentationTopic/PrimaryContent/RestParameters.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<template>
1212
<OnThisPageSection :anchor="anchor" :title="title">
13-
<SectionTitle :anchor="anchor">{{ title }}</SectionTitle>
13+
<LinkableHeading :anchor="anchor">{{ title }}</LinkableHeading>
1414
<ParametersTable :parameters="parameters" :changes="parameterChanges">
1515
<template slot="symbol" slot-scope="{ name, type, content, changes, deprecated }">
1616
<div class="param-name" :class="{ deprecated: deprecated }">
@@ -55,7 +55,7 @@
5555
import { anchorize } from 'docc-render/utils/strings';
5656
import ContentNode from 'docc-render/components/DocumentationTopic/ContentNode.vue';
5757
import OnThisPageSection from 'docc-render/components/DocumentationTopic/OnThisPageSection.vue';
58-
import SectionTitle from 'docc-render/components/ContentNode/SectionTitle.vue';
58+
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
5959
6060
import WordBreak from 'docc-render/components/WordBreak.vue';
6161
import apiChangesProvider from 'docc-render/mixins/apiChangesProvider';
@@ -77,7 +77,7 @@ export default {
7777
ContentNode,
7878
OnThisPageSection,
7979
ParametersTable,
80-
SectionTitle,
80+
LinkableHeading,
8181
},
8282
props: {
8383
title: {

src/components/DocumentationTopic/PrimaryContent/RestResponses.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<template>
1212
<OnThisPageSection :anchor="anchor" :title="title">
13-
<SectionTitle :anchor="anchor">{{ title }}</SectionTitle>
13+
<LinkableHeading :anchor="anchor">{{ title }}</LinkableHeading>
1414
<ParametersTable :parameters="responses" :changes="propertyChanges" key-by="status">
1515
<template slot="symbol" slot-scope="{ status, type, reason, content, changes }">
1616
<div class="response-name">
@@ -51,7 +51,7 @@
5151

5252
<script>
5353
import { anchorize } from 'docc-render/utils/strings';
54-
import SectionTitle from 'docc-render/components/ContentNode/SectionTitle.vue';
54+
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
5555
import ContentNode from 'docc-render/components/DocumentationTopic/ContentNode.vue';
5656
import OnThisPageSection from 'docc-render/components/DocumentationTopic/OnThisPageSection.vue';
5757
@@ -69,7 +69,7 @@ export default {
6969
ContentNode,
7070
OnThisPageSection,
7171
ParametersTable,
72-
SectionTitle,
72+
LinkableHeading,
7373
},
7474
props: {
7575
title: {

src/components/DocumentationTopic/Relationships.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
v-for="section in sectionsWithSymbols"
1818
:key="section.type"
1919
:title="section.title"
20+
:anchor="section.anchor"
2021
>
2122
<List :symbols="section.symbols" :type="section.type" />
2223
</Section>

src/components/DocumentationTopic/TopicsTable.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
v-for="section in sectionsWithTopics"
1515
:key="section.title"
1616
:title="section.title"
17+
:anchor="section.anchor"
1718
>
1819
<template v-if="wrapTitle" slot="title">
19-
<SectionTitle tag="h3" :anchor="anchor" class="title">
20+
<LinkableHeading :level="3" :anchor="anchor" class="title">
2021
<WordBreak>{{ section.title }}</WordBreak>
21-
</SectionTitle>
22+
</LinkableHeading>
2223
</template>
2324
<template v-if="section.abstract" slot="abstract">
2425
<ContentNode :content="section.abstract" />
@@ -41,7 +42,7 @@
4142
<script>
4243
import ContentNode from 'docc-render/components/DocumentationTopic/ContentNode.vue';
4344
import WordBreak from 'docc-render/components/WordBreak.vue';
44-
import SectionTitle from 'docc-render/components/ContentNode/SectionTitle.vue';
45+
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
4546
import ContentTable from './ContentTable.vue';
4647
import ContentTableSection from './ContentTableSection.vue';
4748
import TopicsLinkBlock from './TopicsLinkBlock.vue';
@@ -61,7 +62,7 @@ export default {
6162
TopicsLinkBlock,
6263
ContentNode,
6364
ContentTableSection,
64-
SectionTitle,
65+
LinkableHeading,
6566
},
6667
props: {
6768
isSymbolDeprecated: Boolean,

src/mixins/scrollToElement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default {
3131
* Always scroll to the element and focus it.
3232
* This ensures that the next tab target is inside
3333
* and that it is in view, even if the hash is in the url
34-
* @returns {Promise<void>}
34+
* @returns {Promise<Element>}
3535
*/
3636
async handleFocusAndScroll(hash) {
3737
const element = document.getElementById(hash);

tests/unit/components/ContentNode.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import FigureCaption from 'docc-render/components/ContentNode/FigureCaption.vue'
2020
import InlineImage from 'docc-render/components/ContentNode/InlineImage.vue';
2121
import Reference from 'docc-render/components/ContentNode/Reference.vue';
2222
import Table from 'docc-render/components/ContentNode/Table.vue';
23-
import SectionTitle from 'docc-render/components/ContentNode/SectionTitle.vue';
23+
import LinkableHeading from 'docc-render/components/ContentNode/LinkableHeading.vue';
2424
import StrikeThrough from 'docc-render/components/ContentNode/StrikeThrough.vue';
2525

2626
const { TableHeaderStyle } = ContentNode.constants;
@@ -153,17 +153,17 @@ describe('ContentNode', () => {
153153

154154
describe('with type="heading"', () => {
155155
it('renders a <h*>', () => {
156-
for (let level = 1; level <= 6; level += 1) {
156+
for (let level = 1; level < 6; level += 1) {
157157
const wrapper = mountWithItem({
158158
type: 'heading',
159159
anchor: 'heading',
160160
level,
161161
text: 'heading',
162162
});
163163

164-
const sectionTitle = wrapper.find('.content').find(SectionTitle);
164+
const sectionTitle = wrapper.find('.content').find(LinkableHeading);
165165
expect(sectionTitle.exists()).toBe(true);
166-
expect(sectionTitle.attributes('tag')).toBe(`h${level}`);
166+
expect(sectionTitle.props('level')).toBe(level);
167167
expect(sectionTitle.attributes('anchor')).toBe('heading');
168168
expect(sectionTitle.isEmpty()).toBe(false);
169169
expect(sectionTitle.text()).toContain('heading');

0 commit comments

Comments
 (0)