Skip to content

Commit ac200c5

Browse files
committed
Convert breadcrumbs into router links to support cmd/ctrl-click
Signed-off-by: Andrew Sawers <ajmsawers@gmail.com>
1 parent afafda1 commit ac200c5

1 file changed

Lines changed: 45 additions & 21 deletions

File tree

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,61 @@
11
import { Breadcrumbs, Link, Typography } from '@mui/material';
2-
import { useNavigate } from 'react-router-dom';
2+
import { Link as RouterLink } from 'react-router-dom';
33
import { IFFBreadcrumb } from '../../interfaces';
44

55
interface Props {
66
breadcrumbs: IFFBreadcrumb[];
77
}
88

99
export const FFBreadcrumb: React.FC<Props> = ({ breadcrumbs }) => {
10-
const navigate = useNavigate();
11-
1210
return (
1311
<Breadcrumbs>
14-
{breadcrumbs.map((b, idx) => (
15-
<Link
16-
key={idx}
17-
underline={idx !== breadcrumbs.length - 1 ? 'hover' : 'none'}
18-
color={idx !== breadcrumbs.length - 1 ? 'inherit' : 'text.primary'}
19-
sx={{
20-
cursor: idx !== breadcrumbs.length - 1 ? 'pointer' : 'default',
21-
}}
22-
onClick={b.link ? () => navigate(b.link ?? '') : undefined}
23-
>
24-
<Typography
25-
variant="h5"
12+
{breadcrumbs.map((b, idx) => {
13+
const isLast = idx === breadcrumbs.length - 1;
14+
const link = b.link;
15+
if (link && !isLast) {
16+
return (
17+
<Link
18+
key={idx}
19+
component={RouterLink}
20+
to={link}
21+
underline="hover"
22+
color="inherit"
23+
sx={{ cursor: 'pointer' }}
24+
>
25+
<Typography
26+
variant="h5"
27+
sx={{
28+
fontWeight: 'bold',
29+
fontSize: '14',
30+
}}
31+
>
32+
{b.content}
33+
</Typography>
34+
</Link>
35+
);
36+
}
37+
38+
return (
39+
<Link
40+
key={idx}
41+
underline={!isLast ? 'hover' : 'none'}
42+
color={!isLast ? 'inherit' : 'text.primary'}
2643
sx={{
27-
fontWeight: 'bold',
28-
fontSize: '14',
44+
cursor: 'default',
2945
}}
3046
>
31-
{b.content}
32-
</Typography>
33-
</Link>
34-
))}
47+
<Typography
48+
variant="h5"
49+
sx={{
50+
fontWeight: 'bold',
51+
fontSize: '14',
52+
}}
53+
>
54+
{b.content}
55+
</Typography>
56+
</Link>
57+
);
58+
})}
3559
</Breadcrumbs>
3660
);
3761
};

0 commit comments

Comments
 (0)