-
Notifications
You must be signed in to change notification settings - Fork 27.6k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Link API breaks a11y intuition #5533
Comments
Had to override one of the link accesibility lints due to nextjs bug vercel/next.js#5533
Had to override one of the link accesibility lints due to nextjs bug vercel/next.js#5533
@timneutkens Would you accept a PR that would uses a similar approach like this? It would be a pretty big breaking change but imo it's worth it. I think the current |
Any progress on this? running into the same issue trying to setup tests for |
We had to use the following solution https://github.com/evcohen/eslint-plugin-jsx-a11y/issues/402#issuecomment-368305051, but it would be nice to have other options. |
Worth pointing out that the above solution (https://github.com/evcohen/eslint-plugin-jsx-a11y/issues/402#issuecomment-368305051) disables the rule's check for an |
Yes, I would agree with/echo @WestonThayer's point! The point of having the accessibility plugin is to audit for cases where we aren't supporting important rules. If the fundamental Linking structure of Next doesn't allow for us to check if we're being compliant, we'll have to continue manually do this checking in our process or handle it later on in our build process (adding more unnecessary dev time). |
Isn't this a limitation of styled-jsx? Anchor rendered by Links wouldn't have styles applied. |
Any news on this issue, or a good workaround that doesn't disable the href-rule? |
@renet build the Link we want from the Link we get
import NextLink, { LinkProps as NextLinkProps } from "next/link";
import { ComponentProps } from "react";
export interface LinkProps
extends NextLinkProps,
Omit<ComponentProps<"a">, keyof NextLinkProps> {}
export const Link = ({
href,
as,
replace,
scroll,
shallow,
passHref,
prefetch,
...rest
}: LinkProps) => (
<NextLink
href={href}
as={as}
replace={replace}
scroll={scroll}
shallow={shallow}
passHref={passHref}
prefetch={prefetch}
>
{/* href is passed by NextLink */}
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid, jsx-a11y/anchor-has-content */}
<a {...rest} />
</NextLink>
); |
This issue from 2018 is still relevant. All three solutions proposed in the original post are great. They're called out as breaking changes but I would point out that the current api could continue to be supported, making it a non-breaking change. Simply adding any of those 3 options would make Next.js play nicely with jsx-a11y. |
I think this is really important. Right now, Next.js is competing with Gatsby and I've realized very quickly that I cannot use Next.js due to the lack of accessibility support. Accessibility is highly important and should be a priority (and goes further than just complying with jsx-a11y). |
Also running into this. I am using nx.dev with nextjs which sets up jsx-a11y for me. I'd hate to have to disable the eslint rule globally as there will be anchor link without Link parent for example external links |
Hitting this with an old school bump. Still an issue in 2021, and taking off the a11y guardrails linting is not an option for big teams and projects. |
An alternative (but hacky) solution is to enable the
|
We're still working on solving this. It's more complicated than you're making it out to be as you're not considering the hundreds of thousands existing Next.js applications that would not be able to upgrade to a version that has the proposed solution in this issue. In Next.js 10 we introduced https://nextjs.org/blog/next-10#automatic-resolving-of-href as an incremental step towards this. And there's an open RFC to build on top of that: #8207 to enable |
A codemod would be great. Alternatively a eslint plugin that extends from the a11y one but allows anchors without href if they are wrapped in a Link tag |
Excited to see progress on this. While waiting for a longer term solution, I've been using a utility component that handles the creation of the |
RFC: #8207 |
I have a question regarding this issue: Omitting the a-tag and only having text inside the Link Component seems to work, because of the following part of the code for next/link:
What are the downsides to using this as a workaround? P.S.: The comment says, |
This comment has been minimized.
This comment has been minimized.
I was taking a look on this issue and I thought if this would be a good workaround:
|
Hi guys, any news on how to handle this properly? |
@timneutkens - It would be nice if this temporary solution was included in Next.js's Link documentation. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Feature request
I want a more intuitive
Link
API which respects expectations we have around nativea
tags.Is your feature request related to a problem? Please describe.
The current link API looks like the following:
This is problematic for a few reasons:
a
tag without anhref
, alarm bells go off, because that is a UX anti-pattern. In fact, this API makes it impossible to appease theanchor-is-valid
eslint-plugin-jsx-a11y rule (see https://github.com/evcohen/eslint-plugin-jsx-a11y/issues/402).cloneElement
which should be avoided as its behavior is confusing. (How would I know mya
tag will be given anhref
? Nothing about this API suggests that.)Describe the solution you'd like
I would like a solution which doesn't require you to type an
a
tag without anhref
and also doesn't require you to duplicate thehref
information.Describe alternatives you've considered
There are a few good alternatives:
a
tag if no children are given:This is the approach react-router uses and it works quite well.
This method appeases the
anchor-is-valid
rule and doesn't require the user to duplicate href information since the build href is passed down to the component they are rendering.A combination of 1 and 2 would be powerful enough to cover all reasonable use cases.
Additional context
6431f5f
The text was updated successfully, but these errors were encountered: