Skip to content

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

Merged
pksjce merged 13 commits into
mainfrom
pk/button-issue
Mar 21, 2022
Merged

Icon button fixes: Removes iconLabel and adds aria-label to the type#1945
pksjce merged 13 commits into
mainfrom
pk/button-issue

Conversation

@pksjce

Copy link
Copy Markdown
Contributor

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 rezrahMarch 10, 2022 08:17
@changeset-bot

changeset-botBot commented Mar 10, 2022

Copy link
Copy Markdown

🦋 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
NameType
@primer/reactPatch

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

github-actionsBot commented Mar 10, 2022

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
dist/browser.esm.js63.19 KB (-0.08% 🔽)
dist/browser.umd.js63.56 KB (-0.06% 🔽)

Comment threadsrc/Button/types.ts Outdated
@@ -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
Copy Markdown
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?

Comment threadsrc/Button/types.ts Outdated
*/
icon: React.FunctionComponent<IconProps>
iconLabel: string
'aria-label': string

@rezrahrezrahMar 10, 2022

Copy link
Copy Markdown
Contributor

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?

@siddharthkpsiddharthkpMar 10, 2022

Copy link
Copy Markdown
Member

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
Copy Markdown
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

<buttonaria-label="Edit this file"><svg>{/* paths and stuff */}</svg></button><div>Editthisfile</div>//<---thisisatooltip

OR

<buttonaria-labelledby="editTooltip"><svg>{/* paths and stuff */}</svg></button><divid="editTooltip">Editthisfile</div>//<---thisisatooltip

When the tooltip is acting like helper/caption text

<buttonaria-label="Edit this file"aria-describedby="editTooltip"><svg>{/* paths and stuff */}</svg></button><divid="editTooltip">Onlypeopleinthisorganizationcaneditthisfile</div>//<---thisisatooltip

@alliethu - please keep me correct

Copy link
Copy Markdown
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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

@khiga8khiga8Mar 10, 2022

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

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 🤞


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
Copy Markdown
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 container = render(<IconButton icon={SearchIcon} aria-label="Search button" />)
const IconOnlyButton = await container.findByRole('button')
expect(IconOnlyButton).toHaveStyleRule('padding-right', '8px')
expect(IconOnlyButton).toMatchSnapshot()

Copy link
Copy Markdown
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)

@pksjce
pksjceforce-pushed the pk/button-issue branch 2 times, most recently from 299fe5e to 00691a9CompareMarch 15, 2022 09:20

@rezrahrezrah left a comment

Copy link
Copy Markdown
Contributor

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 🙌

@siddharthkpsiddharthkp left a comment

Copy link
Copy Markdown
Member

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 ✨

@siddharthkpsiddharthkp left a comment

Copy link
Copy Markdown
Member

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:

@pksjce
pksjce enabled auto-merge (squash) March 17, 2022 04:09
```jsx live
<>
<IconButton aria-label="Search" size="small" icon={SearchIcon} />
<IconButton aria-label="Search" size="small" icon={SearchIcon} />

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oops, my bad!

@pksjce
pksjce merged commit ef3b58a into mainMar 21, 2022
@pksjce
pksjce deleted the pk/button-issue branch March 21, 2022 08:26
@primer-cssprimer-css mentioned this pull request Mar 21, 2022
Sign up for freeto 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.

6 participants

@pksjce@siddharthkp@mperrotti@alliethu@rezrah@khiga8