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

fix(button): remove role="button" from button styled anchors #5522

Merged
merged 14 commits into from
Mar 6, 2020
Merged

fix(button): remove role="button" from button styled anchors #5522

merged 14 commits into from
Mar 6, 2020

Conversation

dakahn
Copy link
Contributor

@dakahn dakahn commented Mar 4, 2020

Closes #5521
Closes #5112

Implicit labeling (having wrapped text in the sub-tree acting as the label) only works for native button elements. For instances where the button is an anchor tag, p tag or otherwise we need to specify the label with text matching the visible label.

Changelog

New

  • added an aria-label: children to the anchorProps object
  • removed role="button"

Testing / Reviewing

Since button is a widely used generic component I could totally be missing something/some use case. Otherwise just open up Chrome and run DAP with the latest ruleset and you should see zero errors reported 🏄

@dakahn dakahn requested a review from a team as a code owner March 4, 2020 00:43
@ghost ghost requested review from abbeyhrt and tw15egan March 4, 2020 00:43
@netlify
Copy link

netlify bot commented Mar 4, 2020

Deploy preview for carbon-elements ready!

Built with commit 3a3a336

https://deploy-preview-5522--carbon-elements.netlify.com

@netlify
Copy link

netlify bot commented Mar 4, 2020

Deploy preview for carbon-components-react ready!

Built with commit 3a3a336

https://deploy-preview-5522--carbon-components-react.netlify.com

@asudoh
Copy link
Contributor

asudoh commented Mar 4, 2020

A question; What happens if the button has non-text content?

@dakahn
Copy link
Contributor Author

dakahn commented Mar 4, 2020

@asudoh Well, if there was no label whatsoever DAP would throw and error for an anchor tag not having an associated label. Is that a use case we support? For an icon I thought we set a label on the svg.

2020-03-04 10_25_52-Storybook

Copy link
Contributor

@abbeyhrt abbeyhrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Separately, I see that DAP is saying that p and a are form control elements, are they really? Or am I misunderstanding and it's just picking up the role='button'?

@dakahn
Copy link
Contributor Author

dakahn commented Mar 4, 2020

@abbeyhrt right yeah! They become form control elements the moment we designate them role="button"

@joshblack
Copy link
Contributor

Wow, definitely an awkward violation lol. Would you want to add a quick test to check for this too with any links to refer to why we need to do this?

@dakahn
Copy link
Contributor Author

dakahn commented Mar 4, 2020

@joshblack added test! Though you'll notice we we had two nested divs inside our test button that I removed -- they didn't seem to be directly related to any of the tests I saw in that unit, but there might be something I'm missing.

@asudoh
Copy link
Contributor

asudoh commented Mar 4, 2020

@dakahn You could detect if children is a string. If it's the case you can still propagate it to aria-label. Otherwise we can let application to populate aria-label.

@joshblack
Copy link
Contributor

That's a great point ☝️, children is of type PropTypes.node so may not contain text. Would we instead need a prop type warning such that aria-label is required if href is supplied?

@dakahn
Copy link
Contributor Author

dakahn commented Mar 4, 2020

Hey @joshblack brought up a good point that it probably makes more sense to simply remove role="button" for any anchors or whatever other non <button> elements we're only styling like buttons. 👍

@dakahn dakahn requested review from joshblack and abbeyhrt March 4, 2020 22:49
@dakahn dakahn changed the title fix(button): add aria label to non button element buttons fix(button): remove role="button" from button styled anchors Mar 4, 2020
@abbeyhrt
Copy link
Contributor

abbeyhrt commented Mar 5, 2020

@dakahn I'm not really sure how the non-button elements styled to look like buttons are used but is it a problem that they're no longer announced as buttons?

@tw15egan
Copy link
Collaborator

tw15egan commented Mar 5, 2020

@abbeyhrt my understanding is they are used when you are navigating to different parts of an app, so I think it would make more sense that they were not announced as buttons. I believe they are just styled like them since a lone link doesn't seem to have the same affordance/CTA as a button.

@abbeyhrt
Copy link
Contributor

abbeyhrt commented Mar 5, 2020

@tw15egan Ah gotcha, makes sense! Thanks for explaining!

Copy link
Collaborator

@tw15egan tw15egan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, DAP errors have been eliminated ☠️

👍 ✅

Copy link
Contributor

@asudoh asudoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍 - Thanks @dakahn!

@dakahn dakahn merged commit fc2b2a9 into carbon-design-system:master Mar 6, 2020
joshblack added a commit to joshblack/carbon that referenced this pull request Mar 10, 2020
…design-system#5522)

* fix(Dropdown): rely on list-box height closes carbon-design-system#4916

* fix(button): add aria label to non button element button

* test(button): add a test checking that <a> button's get an aria-label

* fix(button): undo previous changes; remove role=button for anchor

* test(button): remove unneeded test for role

Co-authored-by: TJ Egan <[email protected]>
Co-authored-by: Josh Black <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Default button has 3 DAP errors <Button href="xyz"> missing label
6 participants