Skip to content

Commit c72bdf7

Browse files
authored
[on-this-page] Only use word break hints for symbol title (#701)
Resolves: rdar://107193315
1 parent 715eb13 commit c72bdf7

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

src/components/OnThisPageNav.vue

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
class="base-link"
2121
@click.native="handleFocusAndScroll(item.anchor)"
2222
>
23-
<WordBreak v-if="item.i18n">{{ $t(item.title) }}</WordBreak>
24-
<WordBreak v-else>{{ item.title }}</WordBreak>
23+
<component :is="getWrapperComponent(item)">
24+
{{ getTextContent(item) }}
25+
</component>
2526
</router-link>
2627
</li>
2728
</ul>
@@ -122,6 +123,12 @@ export default {
122123
'child-item': item.level === 3,
123124
};
124125
},
126+
getTextContent(item) {
127+
return item.i18n ? this.$t(item.title) : item.title;
128+
},
129+
getWrapperComponent(item) {
130+
return item.isSymbol ? WordBreak : 'span';
131+
},
125132
},
126133
};
127134
</script>

src/mixins/onThisPageRegistrator.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
import ContentNode from 'docc-render/components/DocumentationTopic/ContentNode.vue';
1919
import { AppTopID } from 'docc-render/constants/AppTopID';
2020

21+
const SYMBOL_KIND = 'symbol';
22+
2123
/**
2224
* Crawls the `topicData` of a page, and extracts onThisPage sections.
2325
*/
@@ -44,11 +46,13 @@ export default {
4446
defaultImplementationsSections,
4547
relationshipsSections,
4648
seeAlsoSections,
49+
kind,
4750
} = topicData;
4851
this.store.addOnThisPageSection({
4952
title,
5053
anchor: AppTopID,
5154
level: 1,
55+
isSymbol: kind === SYMBOL_KIND,
5256
}, { i18n: false });
5357
if (primaryContentSections) {
5458
primaryContentSections.forEach((section) => {

tests/unit/components/OnThisPageNav.spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jest.mock('docc-render/utils/throttle', () => jest.fn(v => v));
1919
jest.mock('docc-render/utils/loading', () => ({ waitFrames: jest.fn() }));
2020
const sections = [
2121
{
22-
title: 'Title', level: 1, anchor: AppTopID, i18n: false,
22+
title: 'Title', level: 1, anchor: AppTopID, i18n: false, isSymbol: true,
2323
},
2424
{
2525
title: 'First', level: 2, anchor: 'first', i18n: false,
@@ -110,12 +110,14 @@ describe('OnThisPageNav', () => {
110110
// assert first parent is active
111111
expect(firstParent.classes()).not.toContain('active');
112112
expect(parentLink1.props('to')).toEqual(`?language=objc#${sections[0].anchor}`);
113-
expect(parentLink1.find(WordBreak).text()).toBe(sections[0].title);
113+
const wbreak = parentLink1.find(WordBreak);
114+
expect(wbreak.exists()).toBe(true);
115+
expect(wbreak.text()).toBe(sections[0].title);
114116
// assert second parent
115117
const secondParent = parents.at(1);
116118
expect(secondParent.classes()).toContain('active');
117119
expect(secondParent.find(RouterLinkStub).props('to')).toEqual(`?language=objc#${sections[1].anchor}`);
118-
expect(secondParent.find(WordBreak).text()).toBe(sections[1].title);
120+
expect(secondParent.text()).toBe(sections[1].title);
119121
// assert "children" items
120122
const children = wrapper.findAll('.child-item');
121123
expect(children).toHaveLength(1);

tests/unit/mixins/__snapshots__/onThisPageRegistrator.spec.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Array [
55
Object {
66
"anchor": "app-top",
77
"i18n": false,
8+
"isSymbol": false,
89
"level": 1,
910
"title": "PageTitle",
1011
},

tests/unit/mixins/onThisPageRegistrator.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ describe('OnThisPageRegistrator', () => {
112112
wrapper.setData({
113113
topicData: {
114114
metadata: { title: 'Foo' },
115+
kind: 'symbol',
115116
primaryContentSections: [
116117
{
117118
kind: SectionKind.content,
@@ -134,6 +135,7 @@ describe('OnThisPageRegistrator', () => {
134135
i18n: false,
135136
level: 1,
136137
title: 'Foo',
138+
isSymbol: true,
137139
},
138140
{
139141
anchor: 'provided-heading-anchor',
@@ -185,6 +187,7 @@ describe('OnThisPageRegistrator', () => {
185187
i18n: false,
186188
level: 1,
187189
title: 'Foo',
190+
isSymbol: false,
188191
},
189192
{
190193
anchor: 'provided-heading-anchor',
@@ -212,6 +215,7 @@ describe('OnThisPageRegistrator', () => {
212215
expect(onThisPageSectionsStoreBase.state.onThisPageSections).toHaveLength(16);
213216
wrapper.vm.topicData = {
214217
metadata: { title: 'Foo' },
218+
kind: 'symbol',
215219
primaryContentSections: [
216220
{
217221
kind: SectionKind.content,
@@ -226,6 +230,7 @@ describe('OnThisPageRegistrator', () => {
226230
i18n: false,
227231
level: 1,
228232
title: 'Foo',
233+
isSymbol: true,
229234
},
230235
{
231236
anchor: 'provided-heading-anchor',

0 commit comments

Comments
 (0)