Created
October 12, 2023 14:18
-
-
Save henettaja/cebd374ff7bb7fd571f090a363b5d3ff to your computer and use it in GitHub Desktop.
Accessible Next.js Link with MUI Button styles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ButtonProps } from '@mui/material' | |
import NextLink from 'next/link' | |
/* Using the `linkComponent` prop of MUI's Button component we can give it | |
* the expected behavior in terms of overall accessibility | |
* (screen readers, keyboard navigation etc.) | |
* | |
* The can be done with MUI's Link component by using its `component` prop. | |
* | |
* This works in Next.js 13 and later, thanks to changes in NextLink's behavior. | |
*/ | |
export default function AccessibleNavButton(props?: ButtonProps) { | |
return ( | |
<Button | |
{...props} | |
LinkComponent={NextLink} | |
> | |
Navigation link | |
</Button> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment