-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix(button): check if !disabled before rendering as an anchor if href is provided #4480
fix(button): check if !disabled before rendering as an anchor if href is provided #4480
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.
Hi 👋 thank you for jumping in! As I stated in the original issue, I'd prefer CSS-only solution.
Thanks @asudoh! My one hesitation with a css-only solution is accessibility 🤔 In VoiceOver, even if I add Whereas if I render it as a button element with a disabled state, it is ignored by VO. (@dakahn what do you think?) |
Deploy preview for the-carbon-components ready! Built with commit 7fced60 https://deploy-preview-4480--the-carbon-components.netlify.com |
@jendowns What happens if we add |
Deploy preview for carbon-elements ready! Built with commit 7fced60 |
Deploy preview for carbon-components-react ready! Built with commit 7fced60 https://deploy-preview-4480--carbon-components-react.netlify.com |
Hey @asudoh, adding Good things about this approachWith With So combining the 2 makes it so the anchor cannot be interacted with, and makes it so that VO reads it as "dimmed" (though note that you can still tab to the element, unlike a Concerns about this approachEven the My concern about making an anchor non-interactive is that it subverts the purpose of the anchor... if an anchor isn't supposed to be clicked (and is, for example, The only reason this approach ends up working is due to You can still tab to this anchor though. I don't really care for this approach, as it seems to be getting around some rules and ignoring the purpose of a link. That's why, originally, I wanted to render it as a button element outright -- because you can set a button to a I can be convinced otherwise, but I'm really hesitant to combine an aria with a css rule. I'm really curious what @dakahn thinks about this 🤔 |
This solution seems ideal to me and reads and works well with VoiceOver and JAWS, @asudoh what is the reason behind your preference for a CSS-only solution? |
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.
Disabled links are bad. They subvert a core interaction on the web in a way that users of all kinds can find confusing and unexpected. I like Jen's proposed solution because it speaks well and communicates clearly in a screen reader and avoids aria relying instead on using the right elements in the right place. 👍
OK fair enough, thank you for taking a look and explaining your thoughts @jendowns! |
Closes #4479
Proposal to check if
!disabled
before rendering aButton
as an anchor ifhref
prop is provided. That way, you can ensure that you don't have a situation where a button-like anchor withdisabled={true}
can still be clicked and used to navigate.Changelog
New
Changed
!disabled
before rendering aButton
as an anchor ifhref
is providedTesting / Reviewing
Open the
carbon-components-react
deployment for this PR and then toggle thedisabled
state in the knobs while inspecting the second button in the examples ("Link"). Then try to interact with it while it isdisabled={true}
Then compare to the current storybook: http://react.carbondesignsystem.com/iframe.html?id=buttons--default