Skip to content

Commit 6d70a2a

Browse files
Barthélémy Ledouxsapegin
Barthélémy Ledoux
authored andcommitted
Fix: Single sections can contain only sections (styleguidist#1414)
If a section contains only one subsection, Styleguidist will try to optimize. It will make the section disappear and show its components instead. If this section only contain sections, no components, it should optimize to sections and not to components.
1 parent beeb7cb commit 6d70a2a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/client/rsg-components/TableOfContents/TableOfContents.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ export default class TableOfContents extends Component {
4141
const { sections, useRouterLinks } = this.props;
4242
// If there is only one section, we treat it as a root section
4343
// In this case the name of the section won't be rendered and it won't get left padding
44-
const firstLevel = sections.length === 1 ? sections[0].components : sections;
44+
// Since a section can contain only other sections,
45+
// we need to make sure not to loose the subsections.
46+
// We will treat those subsecttions as the new roots.
47+
const firstLevel =
48+
sections.length === 1 ? sections[0].sections || sections[0].components : sections;
4549
const filtered = filterSectionsByName(firstLevel, searchTerm);
4650

4751
return this.renderLevel(filtered, useRouterLinks);

0 commit comments

Comments
 (0)