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: icon story accessibility #28

Merged
merged 1 commit into from
Jun 24, 2019
Merged

Conversation

jsomsanith
Copy link
Collaborator

What is the problem this PR is trying to solve?
Icon story is not accessible. This is only on the story as we can’t do anything to ensure icon accessibility, it’s more linked to the usage.
On decorative icons we should hide it via aria-hidden, and on icons that hold information, we should set a proper aria-label.

  1. it’s a list but it only uses divs
  2. story with label has decorative icons, they should be hidden to SR
  3. story without labels icons hold information, they should have some text alternatives
  4. stories with inline/block icon should have a text alternative

What is the chosen solution to this problem?

  1. use ul/li
  2. add aria-hidden on the icons
  3. set key as aria-label
  4. set a meaningful aria-label

As suggested by @domyen, a comment in Icon code has been added, giving advice to make it accessible when using it.

@jsomsanith jsomsanith force-pushed the jsomsanith/fix/icon_story_a11y branch from 7db816f to e3bd926 Compare June 24, 2019 21:20
@domyen domyen merged commit c5660f6 into master Jun 24, 2019
@domyen domyen deleted the jsomsanith/fix/icon_story_a11y branch June 24, 2019 21:35
@kylesuss
Copy link
Collaborator

kylesuss commented Jun 24, 2019

I know its a bit late now as this is merged, but I was sketching out an idea to see if we could make this more enforceable based upon your comments @jsomsanith :

const NonDecorativeIcon = ({ label, ...rest }) => (
  <Svg viewBox="0 0 1024 1024" width="20px" height="20px" aria-label={label} {...props}>
    <Path d={icons[icon]} />
  </Svg>
);

NonDecorativeIcon.propTypes = {
  label: PropTypes.string.isRequired,
};

const DecorativeIcon = props => (
  <Svg viewBox="0 0 1024 1024" width="20px" height="20px" aria-hidden {...props}>
    <Path d={icons[icon]} />
  </Svg>
);

const Icon = ({ hasExternalLabel, ...rest }) => {
  if (hasExternalLabel) {
    return <NonDecorativeIcon {...rest} />;
  }

  return <DecorativeIcon {...rest} />;
};

Icon.propTypes = {
  block: PropTypes.bool,
  // This is required so that we don't assume all icons are decorative.
  hasExternalLabel: PropTypes.bool.isRequired,
  icon: PropTypes.string.isRequired,
};

Icon.defaultProps = {
  block: false,
};

export default Icon;

@jsomsanith what do you think about something like this? We can enforce the accessibility attributes this way, but is it overkill?

cc @domyen

@domyen
Copy link
Member

domyen commented Jun 25, 2019 via email

@jsomsanith
Copy link
Collaborator Author

Instead of having an Icon element that switch to Decorative or NonDecorative, I would prefer to expose only the DecorativeIcon and NonDecorativeIcon. So the dev must pick one depending on the purpose. Those 2 components would use the same Icon internal component passing the extra aria-label or aria-hidden from their own required props

@kylesuss
Copy link
Collaborator

I think the aria stuff is hard to remember if you don't even know to consider using it in the first place. Pretty easy to just leave it out at that point. That said, I don't love the verbose nature of requiring the hasExternalLabel prop either -- was just trying to think this through a bit in terms of how the library will be used. It does seem too easy to me to leave the accessibility stuff out. I also prefer having 1 Icon component (vs exposing both DecorativeIcon and NonDecorativeIcon), so maybe that means we have the easiest solution so far and we just have to rely on people checking the design system story docs before using a component.

Seems like a prime use case for docs mode w/ MDX 😉 I think I will use this as a testing ground for some of that documentation.

@kylesuss
Copy link
Collaborator

🚀 PR was released in v0.0.27 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants