Skip to content

Add anchors to ContentTableSection #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/DocumentationTopic/ContentTableSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<div class="contenttable-section">
<div class="section-title">
<slot name="title">
<h3 class="title">{{ title }}</h3>
<h3 class="title" :id="anchor">{{ title }}</h3>
</slot>
</div>
<div class="section-content">
Expand All @@ -31,6 +31,10 @@ export default {
type: String,
required: true,
},
anchor: {
type: String,
default: null,
},
},
};
</script>
Expand Down
1 change: 1 addition & 0 deletions src/components/DocumentationTopic/Relationships.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
v-for="section in sectionsWithSymbols"
:key="section.type"
:title="section.title"
:anchor="section.anchor"
>
<List :symbols="section.symbols" :type="section.type" />
</Section>
Expand Down
1 change: 1 addition & 0 deletions src/components/DocumentationTopic/TopicsTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
v-for="section in sectionsWithTopics"
:key="section.title"
:title="section.title"
:anchor="section.anchor"
>
<template v-if="wrapTitle" slot="title">
<WordBreak tag="h3" class="title">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ describe('ContentTableSection', () => {
expect(title.text()).toBe(propsData.title);
});

it('renders an `id` if `anchor` is provided', () => {
const title = wrapper.find('.title');
expect(title.attributes('id')).toBe(undefined);
wrapper.setProps({
anchor: 'foo-bar',
});
expect(title.attributes('id')).toBe('foo-bar');
});

it('renders a slot for a title', () => {
wrapper = shallowMount(ContentTableSection, {
propsData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('Relationships', () => {
foo.identifier,
bar.identifier,
],
anchor: 'inherits-from',
},
{
type: 'conformsTo',
Expand Down Expand Up @@ -83,6 +84,7 @@ describe('Relationships', () => {

const firstSection = sections.at(0);
expect(firstSection.props('title')).toBe(propsData.sections[0].title);
expect(firstSection.props('anchor')).toBe(propsData.sections[0].anchor);
const firstList = firstSection.find(List);
expect(firstList.exists()).toBe(true);
expect(firstList.props('symbols')).toEqual([
Expand All @@ -93,6 +95,7 @@ describe('Relationships', () => {

const lastSection = sections.at(1);
expect(lastSection.props('title')).toBe(propsData.sections[1].title);
expect(lastSection.props('anchor')).toBe(null);
const lastList = lastSection.find(List);
expect(lastList.exists()).toBe(true);
expect(lastList.props('symbols')).toEqual([baz]);
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/components/DocumentationTopic/TopicsTable.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('TopicsTable', () => {
abstract: [{ type: 'text', text: 'foo abstract' }],
discussion: { type: 'content', content: [{ type: 'text', text: 'foo discussion' }] },
identifiers: [foo.identifier, 'bar'],
anchor: 'foobar',
},
{
title: 'Baz',
Expand Down Expand Up @@ -77,7 +78,9 @@ describe('TopicsTable', () => {
const sections = wrapper.findAll(ContentTableSection);
expect(sections.length).toBe(propsData.sections.length);
expect(sections.at(0).props('title')).toBe(propsData.sections[0].title);
expect(sections.at(0).props('anchor')).toBe(propsData.sections[0].anchor);
expect(sections.at(1).props('title')).toBe(propsData.sections[1].title);
expect(sections.at(1).props('anchor')).toBe(null);
});

it('renders a `TopicsLinkBlock` for each topic with reference data in a section', () => {
Expand Down