Skip to content

Commit 5362fb0

Browse files
eragon512sapegin
authored andcommitted
Fix: Correctly render sections with href in sidebar (styleguidist#1346)
Closes styleguidist#1141
1 parent 0cd533c commit 5362fb0

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import getUrl from '../../utils/getUrl';
66
function ComponentsList({ classes, items, useRouterLinks = false, useHashId, hashPath }) {
77
const mappedItems = items.map(item => ({
88
...item,
9+
shouldOpenInNewTab: !!item.href,
910
href: item.href
1011
? item.href
1112
: getUrl({

src/client/rsg-components/ComponentsList/ComponentsListRenderer.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,20 @@ export function ComponentsListRenderer({ classes, items }) {
4747
const windowHash = window.location.pathname + getHash(window.location.hash);
4848
return (
4949
<ul className={classes.list}>
50-
{items.map(({ heading, visibleName, href, content, external }) => {
50+
{items.map(({ heading, visibleName, href, content, shouldOpenInNewTab }) => {
5151
const isItemSelected = windowHash === href;
5252
return (
5353
<li
54-
className={cx(
55-
classes.item,
56-
(!content || !content.props.items.length) && classes.isChild,
57-
isItemSelected && classes.isSelected
58-
)}
54+
className={cx(classes.item, {
55+
[classes.isChild]: (!content || !content.props.items.length) && !shouldOpenInNewTab,
56+
[classes.isSelected]: isItemSelected,
57+
})}
5958
key={href}
6059
>
6160
<Link
6261
className={cx(heading && classes.heading)}
6362
href={href}
64-
target={external ? '_blank' : undefined}
63+
target={shouldOpenInNewTab ? '_blank' : undefined}
6564
>
6665
{visibleName}
6766
</Link>

src/client/rsg-components/ComponentsList/__snapshots__/ComponentsList.spec.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ exports[`if a custom href is provided, should use it instead of generating inter
88
Object {
99
"href": "http://example.com",
1010
"name": "External example",
11+
"shouldOpenInNewTab": true,
1112
"visibleName": "External example",
1213
},
1314
Object {
1415
"href": "/#input",
1516
"name": "Input",
17+
"shouldOpenInNewTab": false,
1618
"slug": "input",
1719
"visibleName": "Input",
1820
},
@@ -72,12 +74,14 @@ exports[`should set a parameter on link when useHashId is activated 1`] = `
7274
Object {
7375
"href": "/#/Components?id=button",
7476
"name": "Button",
77+
"shouldOpenInNewTab": false,
7578
"slug": "button",
7679
"visibleName": "Button",
7780
},
7881
Object {
7982
"href": "/#/Components?id=input",
8083
"name": "Input",
84+
"shouldOpenInNewTab": false,
8185
"slug": "input",
8286
"visibleName": "Input",
8387
},
@@ -94,11 +98,13 @@ exports[`should set a sub route on link when useHashId is deactivated 1`] = `
9498
Object {
9599
"href": "/#/Components/Button",
96100
"name": "Button",
101+
"shouldOpenInNewTab": false,
97102
"slug": "button",
98103
},
99104
Object {
100105
"href": "/#/Components/Input",
101106
"name": "Input",
107+
"shouldOpenInNewTab": false,
102108
"slug": "input",
103109
},
104110
]
@@ -114,12 +120,14 @@ exports[`should set the correct href for items 1`] = `
114120
Object {
115121
"href": "/#button",
116122
"name": "Button",
123+
"shouldOpenInNewTab": false,
117124
"slug": "button",
118125
"visibleName": "Button",
119126
},
120127
Object {
121128
"href": "/#input",
122129
"name": "Input",
130+
"shouldOpenInNewTab": false,
123131
"slug": "input",
124132
"visibleName": "Input",
125133
},

0 commit comments

Comments
 (0)