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

Icon button fixes: Removes iconLabel and adds aria-label to the type #1945

Merged
merged 13 commits into from
Mar 21, 2022

Conversation

pksjce
Copy link
Collaborator

@pksjce pksjce commented Mar 10, 2022

Describe your changes here.

The documentation and stories for IconButton were not consistent.
The iconLabel is not actually required.
The aria-label should be mandatory for IconButton

Screenshots

Please provide before/after screenshots for any visual changes

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@pksjce pksjce requested review from a team and rezrah March 10, 2022 08:17
@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2022

🦋 Changeset detected

Latest commit: 93a508b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Mar 10, 2022

size-limit report 📦

Path Size
dist/browser.esm.js 63.19 KB (-0.08% 🔽)
dist/browser.umd.js 63.56 KB (-0.06% 🔽)

@@ -45,7 +45,7 @@ export type IconButtonProps = {
* This is to be used if it is an icon-only button. Will make text visually hidden
Copy link
Contributor

Choose a reason for hiding this comment

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

do you need this comment anymore?

@@ -45,7 +45,7 @@ export type IconButtonProps = {
* This is to be used if it is an icon-only button. Will make text visually hidden
*/
icon: React.FunctionComponent<IconProps>
iconLabel: string
'aria-label': string
Copy link
Contributor

@rezrah rezrah Mar 10, 2022

Choose a reason for hiding this comment

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

Should be this required? Also, what would the user do if they wanted to apply aria-labelledby instead, should we have some logic to only apply the aria-label only if aria-labelledby hasn't been passed in so that takes precedence?

Copy link
Member

@siddharthkp siddharthkp Mar 10, 2022

Choose a reason for hiding this comment

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

Related: What's the right way to add a tooltip to an IconButton, like the one on a file?

image

When composable Tooltip + IconButton, does the aria-label go on both of them or just one?

image

This would be useful for trailing action for TextInput (https://github.com/github/primer/issues/748)

👀 @alliethu @mperrotti

Copy link
Contributor

Choose a reason for hiding this comment

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

@siddharthkp - I actually think we'd want the aria-label on the button but not the tooltip.

Here's what I think would give a nice experience for screenreaders

When the tooltip is acting like a label

<button aria-label="Edit this file"><svg>{/* paths and stuff */}</svg></button>
<div>Edit this file</div> // <--- this is a tooltip

OR

<button aria-labelledby="editTooltip"><svg>{/* paths and stuff */}</svg></button>
<div id="editTooltip">Edit this file</div> // <--- this is a tooltip

When the tooltip is acting like helper/caption text

<button aria-label="Edit this file" aria-describedby="editTooltip"><svg>{/* paths and stuff */}</svg></button>
<div id="editTooltip">Only people in this organization can edit this file</div> // <--- this is a tooltip

@alliethu - please keep me correct

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I just realized our tooltips aren't displayed on focus, only hover. :(

We probably need an a11y audit on these

Choose a reason for hiding this comment

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

@mperrotti Yes, the aria-label should be on the button. Also, heads-up that @khiga8 just did a recent release to fix tooltips on our comment box toolbars. Hopefully, you should be able to reference her implementation for the fixes on the PRC end.

https://github.com/github/accessibility/issues/594#issuecomment-1034219464

Choose a reason for hiding this comment

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

@mperrotti even more current, @hectahertz is working on Upstreaming tooltip to PVC. The two of you should coordinate! https://github.com/github/accessibility/issues/802

Copy link
Contributor

@khiga8 khiga8 Mar 10, 2022

Choose a reason for hiding this comment

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

Here is the upstreamed tooltip component. The tooltip is implemented as a custom element. You may refer to implementation custom element here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For this PR, I'll try and support both aria-label and aria-labelled-by in the types. Hope that works 🤞

@@ -91,8 +91,9 @@ describe('Button', () => {
})

it('styles icon only button to make it a square', async () => {
const container = render(<IconButton icon={SearchIcon} iconLabel="Search icon only button" />)
const container = render(<IconButton icon={SearchIcon} aria-label="Search button" />)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should have a separate test for the aria-label / aria-labelledby. thoughts?

also a suggestion for your matcher, to be more specific around looking for the aria-label attributes:

- findByRole('button')
+ getByRole('button', {name: 'Search button'} ) 

I don't think you need use an async matcher? 🤔

const IconOnlyButton = await container.findByRole('button')
expect(IconOnlyButton).toHaveStyleRule('padding-right', '8px')
expect(IconOnlyButton).toMatchSnapshot()
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like aria attributes fall under logic, so I think it's worth adding a separate test for it like..

expect(IconOnlyButton).toHaveAttribute('aria-label', labelThingy)

Copy link
Contributor

@rezrah rezrah left a comment

Choose a reason for hiding this comment

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

Looks great, nice one @pksjce 🙌

Copy link
Member

@siddharthkp siddharthkp left a comment

Choose a reason for hiding this comment

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

Can we update the first example on the docs as well to use aria-label instead of children: IconButton#icon-only-button and on the page for Button: Button#icon-only-button

sorry for not catching this one on the first pass!

we can also remove the "drafts" meta string from code examples now ✨

Copy link
Member

@siddharthkp siddharthkp left a comment

Choose a reason for hiding this comment

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

Found a missing spot, fixed it: 40f8d81

Ship it :shipit:

@@ -94,7 +94,7 @@ A separate component called `IconButton` is used if the action shows only an ico

```jsx live
<>
<IconButton aria-label="Search" size="small" icon={SearchIcon} />
<IconButton aria-label="Search" size="small" icon={SearchIcon} />
Copy link
Member

Choose a reason for hiding this comment

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

oops, my bad!

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.

None yet

6 participants