Skip to content

Commit 83fdb94

Browse files
authored
Fix: Sections with href were always open in new tab, regardless of the external option (styleguidist#1564)
Fixes styleguidist#1559
1 parent f7f06f9 commit 83fdb94

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/client/rsg-components/TableOfContents/TableOfContents.spec.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,49 @@ it('should render components of a single top section as root', () => {
219219
`);
220220
});
221221

222+
it('should render as the link will open in a new window only if external presents as true', () => {
223+
const actual = shallow(
224+
<TableOfContents
225+
sections={[
226+
{
227+
sections: [
228+
{ content: 'intro.md', href: 'http://example.com' },
229+
{ content: 'chapter.md', href: 'http://example.com', external: true },
230+
],
231+
},
232+
]}
233+
/>
234+
);
235+
236+
expect(actual.find('ComponentsList').prop('items')).toMatchInlineSnapshot(`
237+
Array [
238+
Object {
239+
"components": Array [],
240+
"content": undefined,
241+
"forcedOpen": false,
242+
"heading": false,
243+
"href": "http://example.com",
244+
"initialOpen": true,
245+
"sections": Array [],
246+
"selected": false,
247+
"shouldOpenInNewTab": false,
248+
},
249+
Object {
250+
"components": Array [],
251+
"content": undefined,
252+
"external": true,
253+
"forcedOpen": false,
254+
"heading": false,
255+
"href": "http://example.com",
256+
"initialOpen": true,
257+
"sections": Array [],
258+
"selected": false,
259+
"shouldOpenInNewTab": true,
260+
},
261+
]
262+
`);
263+
});
264+
222265
/**
223266
* testing this layer with no mocking makes no sense...
224267
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default class TableOfContents extends Component<TableOfContentsProps> {
7676
heading: !!section.name && children.length > 0,
7777
content,
7878
selected,
79-
shouldOpenInNewTab: !!section.href,
79+
shouldOpenInNewTab: !!section.external && !!section.href,
8080
initialOpen: this.props.tocMode !== 'collapse' || containsSelected,
8181
forcedOpen: !!this.state.searchTerm.length,
8282
};

0 commit comments

Comments
 (0)