Skip to content

Commit

Permalink
Fix: Sections with href were always open in new tab, regardless of th…
Browse files Browse the repository at this point in the history
…e external option (#1564)

Fixes #1559
  • Loading branch information
mitsuruog committed Mar 18, 2020
1 parent f7f06f9 commit 83fdb94
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/client/rsg-components/TableOfContents/TableOfContents.spec.tsx
Expand Up @@ -219,6 +219,49 @@ it('should render components of a single top section as root', () => {
`);
});

it('should render as the link will open in a new window only if external presents as true', () => {
const actual = shallow(
<TableOfContents
sections={[
{
sections: [
{ content: 'intro.md', href: 'http://example.com' },
{ content: 'chapter.md', href: 'http://example.com', external: true },
],
},
]}
/>
);

expect(actual.find('ComponentsList').prop('items')).toMatchInlineSnapshot(`
Array [
Object {
"components": Array [],
"content": undefined,
"forcedOpen": false,
"heading": false,
"href": "http://example.com",
"initialOpen": true,
"sections": Array [],
"selected": false,
"shouldOpenInNewTab": false,
},
Object {
"components": Array [],
"content": undefined,
"external": true,
"forcedOpen": false,
"heading": false,
"href": "http://example.com",
"initialOpen": true,
"sections": Array [],
"selected": false,
"shouldOpenInNewTab": true,
},
]
`);
});

/**
* testing this layer with no mocking makes no sense...
*/
Expand Down
Expand Up @@ -76,7 +76,7 @@ export default class TableOfContents extends Component<TableOfContentsProps> {
heading: !!section.name && children.length > 0,
content,
selected,
shouldOpenInNewTab: !!section.href,
shouldOpenInNewTab: !!section.external && !!section.href,
initialOpen: this.props.tocMode !== 'collapse' || containsSelected,
forcedOpen: !!this.state.searchTerm.length,
};
Expand Down

0 comments on commit 83fdb94

Please sign in to comment.