-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Create a Button with a link-like style, for accessibility #13861
Comments
@rocketraman Do you have something like this in mind? #8818 (comment). This link vs button issue is definitely interesting. I have seen the needs going in the two directions. Some people want a button that looks like a link and some people want a link that looks like a button.
<Button component={NextLink}>
Sign In
</Button> The Link component handles the core link logic, it can be a simple
<Link component="button">
Sign In
</Link> Here are some link component examples:
I'm happy to add this component in the core! |
@oliviertassinari Re. the breadcrumbs, that was just an example in our app -- we probably wouldn't use the breadcrumb component referenced immediately, as we're planning on changing this navigation to another approach. But thanks for the reference, I'll keep it in mind! For accessibility, if you read through the link I posted, it looks like something that initiates a navigation should be a link (but may look like buttons), and things that initiate a non-navigation action should be a button (but may look like a link). So basically, the idea is to divorce the function of the component from the style. I would be happy with a simple |
Isn't that an important aspect of UI that the user can identify what certain elements do? If something looks like a link then it should behave like a link and vice versa. So if your premise is that buttons and links have different behavior (one navigates the other doesn't) then they should look different.
Why is that? What's wrong with So I would be more inclined to add a |
Well, with an SPA its not as obvious as it sounds. For example, say I have a PDF statement download. Its natural from the user's perspective to represent this visually as a link, and in fact if you look at pretty much every billing site out there, that is indeed how they show statements. However, in reality, the operation being performed in an SPA is not generally an immediate navigation, but instead an API request that requests the statement generation, and then opens the link to the generated statement in a popup or something i.e. the fact that it carries out an action rather than a navigation is an implementation detail.
I'm not an accessibility expert, but if I understand the reasoning given at https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md, an anchor tag which doesn't have an href, as would be the case when the anchor tag is initiating the API call described above, is an accessibility problem, as screen readers expect anchor tags to have href attributes. In this case, since there is no href attribute, using an See also the discussion in this github issue: facebook/create-react-app#4141 |
@rocketraman Yes, I'm sorry about it. I have updated my comment. I'm all in for a This approach focuses on the UI output first rather than on the behavior. The advantage is that we can accept any unstyled link component (react-router, next.js, etc.)
@eps1lon I agree with your point, I have fought hard against mixing the concerns at onepixel.com. But eventually, I had to support this use case. @rocketraman has a very good example, a better one than I have. We could add a note about it too in the documentation. Now, if you follow the Gestalt theory, https://en.m.wikipedia.org/wiki/Gestalt_psychology. They advocate that the human brain has been trained for centuries to create patterns outside of a noisy world, that past experiences are very important. I do believe people are already used to the mixing of concern. Look at the Amazon cart for instance. |
When it comes to the implementation wouldn't something like a |
@el1f Depends, what if you want to actually render a link? What would you rather do: <Button variant="link" component={RouterLink} /> <Link component={RouterLink} /> I would go with option 2. |
Ok, now I see where the issue lies. Option 2 is definitely the preferrable option to have |
I like the flexibility of option 2 as well. |
<!-- Thanks so much for your PR, your contribution is appreciated! ❤️ --> - [x] I have followed (at least) the [PR section of the contributing guide](https://github.com/mui-org/material-ui/blob/master/CONTRIBUTING.md#submitting-a-pull-request). Closes #13861 Closes #14002 Demo: https://deploy-preview-14093--material-ui.netlify.com/style/links/ Potential Todos: - [ ] Make the demo page better - [ ] Demo the inline property on `Typography`
Hi, I'm not sure If It's right to ask here, but this is the only post that dicusss about Sorry for my newbie question, hope someone could help me figure out 😆 |
It looks like "ButtonLink" made it in. I'm looking for "LinkButton" where it renders an |
Seems like it does: https://stackoverflow.com/questions/51642532/how-to-make-a-material-ui-react-button-act-as-a-react-router-dom-link |
I have added https://next.material-ui.com/guides/routing/ in the SO answer. |
<Link
component="button"
onClick={handleClick}
>
Button but looks like a link
</Link> credit @shoshana-solomyak |
Expected Behavior 🤔
For accessibility reasons, it is important that user actions be driven by buttons. However, often times people still use an anchor without an href, because they want the look-and-feel of a link. But this loses the accessibility benefits of using a button. This is now a lint rule in eslint that is enabled by default in create-react-app 2 based apps -- see https://github.com/evcohen/eslint-plugin-jsx-a11y/blob/master/docs/rules/anchor-is-valid.md.
To make fixing this easy, it would be great if a material-ui button could be styled exactly as a link would be using
<a>
, either with an attribute on<Button>
or a new component that uses<button>
under the hood e.g.LinkButton
in the same vein asIconButton
.Current Behavior 😯
One has to try and match the style manually, which is actually not simple.
Examples 🌈
Here is what a link-styled breadcrumb with a downloadable file looks like:
and if using the naive styling with a button:
Context 🔦
Meet accessibility concerns by making it easy to replace links with buttons.
The text was updated successfully, but these errors were encountered: