Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint rule for using <Link> without <a> child and ensuring passHref is used #23713

Closed
leerob opened this issue Apr 6, 2021 · 4 comments · Fixed by #24670
Closed

ESLint rule for using <Link> without <a> child and ensuring passHref is used #23713

leerob opened this issue Apr 6, 2021 · 4 comments · Fixed by #24670
Assignees

Comments

@leerob
Copy link
Member

leerob commented Apr 6, 2021

Describe the feature you'd like to request

Until the RFC for <Link to="/route"> lands solving #5533, we should provide better guidance to users when they're doing something inaccessible.

#8207

Describe the solution you'd like

If you use a <Link> without an <a> child and don't use passHref=true, show a warning.

Describe alternatives you've considered

N/A

@paambaati
Copy link
Contributor

Would this work with component libraries that expose custom components for anchor tags? For example, Chakra-UI has a <Link> tag that I use inside next/link tags with passHref.

@timneutkens timneutkens added this to the 10.x.x milestone Apr 6, 2021
@Timer Timer removed this from the 10.x.x milestone Apr 6, 2021
@leerob
Copy link
Member Author

leerob commented Apr 6, 2021

@paambaati Yeah, that would be fine since it's using passHref.

<Link href="#" passHref>
  <ChakraLink>
    // something
  </ChakraLink>
<Link>

This should show an error when you try to do this:

<Link href="#">
  <ChakraLink>
    // something
  </ChakraLink>
<Link>

@housseindjirdeh housseindjirdeh self-assigned this Apr 6, 2021
@karlhorky
Copy link
Contributor

karlhorky commented Apr 8, 2021

Yeah, I've been looking for this one for over a year now - at @upleveled our students will often use <Link> with some non-interactive element as a child (or sometimes, with a <button> with onClick, which also is problematic).

Up until now, we've just been reviewing their code and telling them to avoid this pattern, but we'd love to enable an ESLint rule! Especially when we get projects as large as this sometimes: https://github.com/uebriges/nextjstravelplaner

@kodiakhq kodiakhq bot closed this as completed in #24670 May 10, 2021
kodiakhq bot pushed a commit that referenced this issue May 10, 2021
Adds a lint rule warning to the Next.js ESLint plugin if `passHref=true` is not assigned for `<Link>` wrapping a custom component.

Fixes #23713
flybayer pushed a commit to blitz-js/next.js that referenced this issue Jun 1, 2021
Adds a lint rule warning to the Next.js ESLint plugin if `passHref=true` is not assigned for `<Link>` wrapping a custom component.

Fixes vercel#23713
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants