-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Ensure Buttons with a url prop output valid HTML #773
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there are two things to consider: The disabled
-related functionality and the styling.
Ensure that the TWO element does not render a disabled attribute in the generated HTML markup.
Thinking about this more, I think it would make sense to convert the "disabled" link to a non-interactive link by removing the href
. That is, if someone produces a "disabled" link, it shouldn't have a valid href
so it can't be accessed. This renders the <a>
but makes it non-interactive.
Another alternative would be to add tabindex="-1"
to the "disabled" link. However, this doesn't convey anything semantic, so I think it's not as clean a solution.
Whichever way we go, I think it would be good to also include a note about how the props can cancel each other out in the props explorer help text.
Would that link still show up when someone using a screen reader pulls the list of all links in the page? If so, this may not be a good solution, as we want the link to be unreachable for everyone. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR fixes the issue, and the HTML is now valid.
Requires additional accessibility work for certain edge cases, but I think we can go ahead and merge.
It would. The negative tabindex just makes it unreachable with the keyboard. To make it hidden to screen reader users, it would also need |
I think this is the preferable solution too. This will require a wee refactor as (sensibly) you can't omit the url property when calling |
Should we still merge this? |
Dragging it up to date now |
Daft realisation: why bother rendering span or a's without hrefs - just render EDIT: Per Devon on Slack: Because buttons get announced in a separate list and it might be odd for someone to hear a disabled button in that list then for it to disappear when it gets enabled (as it is no longer a button) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
// This results in a minimal DOM change when the Button moves between | ||
// enabled and disabled states. | ||
// eslint-disable-next-line jsx-a11y/anchor-is-valid | ||
<a id={id} className={className} aria-label={accessibilityLabel}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this still appear as a navigable anchor in the accessibility tree (just like a good old <a name="foo"></a>
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would a span
be a better idea @dpersing?
src/components/Button/Button.tsx
Outdated
); | ||
} | ||
|
||
// UnstyledLink cant be disabled so always render a button when disabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with this one. The code is clear enough imo.
Always render a `<button disabled>` when rendering disabled Buttons as `<a disabled>` is not valid html
Whoops, I thought I merged this last week! |
WHY are these changes introduced?
Ensure disabled Buttons with a url prop output valid HTML
Fixes #757.
WHAT is this pull request doing?
When a button has a url it is rendered as an
<a>
tag, which does nothave a
disabled
attribute.Stop adding the
disabledattribute in that case.
As disabled is an invalid prop it doesn't do what we were hoping in this contextYou can't click these<a>
tags due topointer-events:none
being set on them, but you can still tab to them using the keyboard.@dpersing / others: We should come up with what we want the expected behaviour to be when rendering a
<Button url="foo" disabled>BAR</Button>
EDIT! Plan made: use an
<a>
without a hrefHow to 🎩
Copy-paste this code in
playground/Playground.tsx
:Ensure that the
<Button disabled url="/foo">TWO</Button>
element does not render adisabled
attribute in the generated HTML markup.