Skip to content

Commit 051424b

Browse files
Kira-Pilotkylecarbs
authored andcommitted
bug: using NavLink for menus (#1530)
* bug: using NavLink for menus resolves #955 * lets fix our story
1 parent 6752f13 commit 051424b

File tree

2 files changed

+31
-33
lines changed

2 files changed

+31
-33
lines changed

site/src/components/BorderedMenu/BorderedMenu.stories.tsx

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,14 @@ export default {
1212

1313
const Template: Story<BorderedMenuProps> = (args: BorderedMenuProps) => (
1414
<BorderedMenu {...args}>
15-
<BorderedMenuRow title="Item 1" description="Here's a description" Icon={BuildingIcon} />
16-
<BorderedMenuRow active title="Item 2" description="This BorderedMenuRow is active" Icon={UsersOutlinedIcon} />
15+
<BorderedMenuRow title="Item 1" description="Here's a description" Icon={BuildingIcon} path="/" />
16+
<BorderedMenuRow
17+
active
18+
title="Item 2"
19+
description="This BorderedMenuRow is active"
20+
Icon={UsersOutlinedIcon}
21+
path="/"
22+
/>
1723
</BorderedMenu>
1824
)
1925

site/src/components/BorderedMenuRow/BorderedMenuRow.tsx

+23-31
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface BorderedMenuRowProps {
1717
/** An SvgIcon that will be rendered to the left of the title */
1818
Icon: typeof SvgIcon
1919
/** URL path */
20-
path?: string
20+
path: string
2121
/** Required title of this row */
2222
title: string
2323
/** Defaults to `"wide"` */
@@ -37,38 +37,30 @@ export const BorderedMenuRow: React.FC<BorderedMenuRowProps> = ({
3737
}) => {
3838
const styles = useStyles()
3939

40-
const Component = () => (
41-
<ListItem
42-
classes={{ gutters: styles.rootGutters }}
43-
className={styles.root}
44-
onClick={onClick}
45-
data-status={active ? "active" : "inactive"}
46-
>
47-
<div className={styles.content} data-variant={variant}>
48-
<div className={styles.contentTop}>
49-
<Icon className={styles.icon} />
50-
<Typography className={styles.title}>{title}</Typography>
51-
{active && <CheckIcon className={styles.checkMark} />}
52-
</div>
40+
return (
41+
<NavLink className={styles.link} to={path}>
42+
<ListItem
43+
classes={{ gutters: styles.rootGutters }}
44+
className={styles.root}
45+
data-status={active ? "active" : "inactive"}
46+
onClick={onClick}
47+
>
48+
<div className={styles.content} data-variant={variant}>
49+
<div className={styles.contentTop}>
50+
<Icon className={styles.icon} />
51+
<Typography className={styles.title}>{title}</Typography>
52+
{active && <CheckIcon className={styles.checkMark} />}
53+
</div>
5354

54-
{description && (
55-
<Typography className={styles.description} color="textSecondary" variant="caption">
56-
{ellipsizeText(description)}
57-
</Typography>
58-
)}
59-
</div>
60-
</ListItem>
55+
{description && (
56+
<Typography className={styles.description} color="textSecondary" variant="caption">
57+
{ellipsizeText(description)}
58+
</Typography>
59+
)}
60+
</div>
61+
</ListItem>
62+
</NavLink>
6163
)
62-
63-
if (path) {
64-
return (
65-
<NavLink to={path} className={styles.link}>
66-
<Component />
67-
</NavLink>
68-
)
69-
}
70-
71-
return <Component />
7264
}
7365

7466
const iconSize = 20

0 commit comments

Comments
 (0)