Skip to content

Commit caa3cf4

Browse files
authored
[Fix]: Enhance link component to support underline styling and improvement (#1739)
### File Changes (3 files modified): 1. `link.js` - Enhanced Link component with configurable underline styling support 2. `src/components/contributors.js` - Applied underline styling to contributor and commit links for better accessibility 3. `table-of-contents.js` - Added underline styling to table of contents navigation links ### Summary: Enhanced the Link component to support optional underline styling through a showUnderline prop and applied underline styling to key navigation elements across the documentation site to improve link visibility and accessibility compliance. ### Changes Overview: - Added showUnderline prop to Link component for configurable text decoration - Applied underlines to contributor profile links and commit date links - Enhanced table of contents with underlined navigation links - Maintained backward compatibility with existing link styling ### Before <img width="359" height="408" alt="image" src="https://github.com/user-attachments/assets/8c953dbf-d57e-45ef-a392-dd5cd4cd63dc" /> <img width="307" height="358" alt="image" src="https://github.com/user-attachments/assets/d0df60bd-ab6a-4d5d-85ec-a1cbca23ac2f" /> ### After <img width="340" height="404" alt="image" src="https://github.com/user-attachments/assets/f5cb22d2-5791-4b37-a7b6-153db79f4d3c" /> <img width="307" height="358" alt="image" src="https://github.com/user-attachments/assets/1e360b38-1974-4b0a-b04e-90586d6692e4" />
1 parent 213100b commit caa3cf4

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/components/link.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,19 @@ const GatsbyLinkWithoutSxProps = React.forwardRef(function GatsbyLinkWithoutSxPr
2626
return <GatsbyLink ref={ref} {...omit(props, 'sx', 'underline', 'hoverColor', 'muted')} />
2727
})
2828

29-
const Link = React.forwardRef(function Link({to, href, ...props}, ref) {
29+
const Link = React.forwardRef(function Link({to, href, showUnderline = false, sx, ...props}, ref) {
3030
const localPath = getLocalPath(href)
3131

32+
const linkStyles = {
33+
...sx,
34+
...(showUnderline && {textDecoration: 'underline'}),
35+
}
36+
3237
if (to || localPath !== null) {
33-
return <PrimerLink ref={ref} as={GatsbyLinkWithoutSxProps} to={to || localPath} {...props} />
38+
return <PrimerLink ref={ref} as={GatsbyLinkWithoutSxProps} to={to || localPath} sx={linkStyles} {...props} />
3439
}
3540

36-
return <PrimerLink ref={ref} href={href} {...props} />
41+
return <PrimerLink ref={ref} href={href} sx={linkStyles} {...props} />
3742
})
3843

3944
export const LinkNoUnderline = React.forwardRef(function LinkNoUnderline({sx, ...props}, ref) {

src/components/page-footer.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,14 @@ const Contributors = ({contributors = [], latestCommit}) => {
4646
</Box>
4747
{latestCommit ? (
4848
<Text sx={{fontSize: 1, mt: 1}}>
49-
Last edited by <Link href={`https://github.com/${latestCommit.login}`}>{latestCommit.login}</Link> on{' '}
50-
<Link href={latestCommit.url}>{format(new Date(latestCommit.date))}</Link>
49+
Last edited by{' '}
50+
<Link href={`https://github.com/${latestCommit.login}`} showUnderline={true}>
51+
{latestCommit.login}
52+
</Link>{' '}
53+
on{' '}
54+
<Link href={latestCommit.url} showUnderline={true}>
55+
{format(new Date(latestCommit.date))}
56+
</Link>
5157
</Text>
5258
) : null}
5359
</>

src/components/table-of-contents.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ const TableOfContentsItems = ({items, depth}) => (
2626
)
2727

2828
const TableOfContents = ({'aria-labelledby': ariaLabelledBy, items, depth = 1, ...props}) => (
29-
<NavList aria-labelledby={ariaLabelledBy} {...props}>
29+
<NavList
30+
aria-labelledby={ariaLabelledBy}
31+
{...props}
32+
sx={{
33+
textDecoration: 'underline',
34+
...props.sx,
35+
}}
36+
>
3037
<TableOfContentsItems items={items} depth={depth} />
3138
</NavList>
3239
)

0 commit comments

Comments
 (0)