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

[Framework/Accessibility] Add kuiScreenReaderOnly class #13133

Conversation

tsullivan
Copy link
Member

The .kuiScreenReaderOnly class makes an element visible to screen readers but not to sighted users. It's important to read the Guide Text provided and the link to the WebAIM site to understand why this class should be used with care.

I tested on a Mac by having the built-in screen reader read the example text:
screen read me

@tsullivan tsullivan requested review from cjcenizal and timroes July 26, 2017 21:30
@cjcenizal cjcenizal added the Team:Platform-Design Team Label for Kibana Design Team. Support the Analyze group of plugins. label Jul 26, 2017
Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

🎈 Woohoo! This is awesome, @tsullivan. I tested this with VoiceOver and can verify that it's screen-reader-accessible. I just had a few comments/suggestions.

}]}
>
<GuideText>
This class can be useful to add accessibiility to older designs that
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: "accessibility".

<GuideText>
This class can be useful to add accessibiility to older designs that
are still in use, but it shouldn't be a permanent solution.
See <a href='http://webaim.org/techniques/css/invisiblecontent/'>http://webaim.org/techniques/css/invisiblecontent/</a> for more information.
Copy link
Contributor

Choose a reason for hiding this comment

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

You can import the GuideLink component on line 8 and use it here, to get the UI Framework documentation styling:

<GuideLink href="http://webaim.org/techniques/css/invisiblecontent/">
  http://webaim.org/techniques/css/invisiblecontent/
</GuideLink>

<p>
This is the first paragraph. It is visible to all.
</p>
<p className='kuiScreenReaderOnly'>
Copy link
Contributor

Choose a reason for hiding this comment

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

Want to make a KuiScreenReaderOnly React component for this as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

I could, but would that be very useful? As a CSS class, it can be applied on any kind of DOM element, but as a React element, it would provide an unnecessary wrapper node. Maybe there is a trick that I don't know though :)

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a cool trick where we can make a component that clones whatever is passed into it and tweaks it slightly. In this case we just want to add a class to that child:

import React, {
  cloneElement,
  PropTypes,
} from 'react';
import classNames from 'classnames';

export const KuiScreenReaderOnly = ({ children }) => {
  const classes = classNames('kuiScreenReaderOnly', children.props.className);

  const props = Object.assign({}, children.props, {
    className: classes,
  };

  return cloneElement(children, props);
};

KuiScreenReaderOnly.propTypes = {
  children: PropTypes.node,
};

We'd use the component like this:

<KuiScreenReaderOnly>
  <p>This is the second paragraph. It is hidden for sighted users but visible to screen readers.</p>
</KuiScreenReaderOnly>

We're doing something similar with our typography components for K7. Do you want to give this a shot in this branch? Or if you prefer we can merge it as-is and make this change separately.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the tip! That doesn't look too hard at all. It's nice that it can still be a functional component.

I don't mind adding this change to this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sweet! Would you also add a test for it please?

@tsullivan tsullivan force-pushed the enhance/framework-accessible-screenreaderonly branch from 834c1fc to b731aec Compare July 31, 2017 17:03
@tsullivan tsullivan force-pushed the enhance/framework-accessible-screenreaderonly branch from b731aec to 940b27e Compare July 31, 2017 17:36
@tsullivan
Copy link
Member Author

@cjcenizal I've added the component and the test. This is ready for re-review

Copy link
Contributor

@cjcenizal cjcenizal left a comment

Choose a reason for hiding this comment

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

LGTM! @timroes Could you take a look too?

Copy link
Member

@pickypg pickypg left a comment

Choose a reason for hiding this comment

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

LGTM!

I wonder if, as a future effort, if we can embed logic inside of the KuiScreenReaderOnly to fail hard if it detects that it is contained as part of other pieces of the UI Framework (implying that it should not be used). Possibly as a conditional thing so that we can avoid leaving hidden text on pages that don't need it after they are redesigned.

@tsullivan
Copy link
Member Author

tsullivan commented Aug 1, 2017

I wonder if, as a future effort, if we can embed logic inside of the KuiScreenReaderOnly to fail hard if it detects that it is contained as part of other pieces of the UI Framework (implying that it should not be used). Possibly as a conditional thing so that we can avoid leaving hidden text on pages that don't need it after they are redesigned.

We chatted about this a little, and I think the important thing to think about is when we see usage of this CSS class, we should treat it the same way we treat a TODO in our code. It will be the mark of a design backlog item. It shouldn't be used a ton, because the design of the page should be navigable and have a visual hierarchy in a way that screen readers can leverage. But until we can start working on those redesigns, this works as a stop-gap.

But even the WebAIM page admits there are rare times when programmers just need to provide an extra hook for accessibility in a way that wouldn't work well for sighted users.

@tsullivan tsullivan merged commit f37eab9 into elastic:master Aug 1, 2017
tsullivan added a commit to tsullivan/kibana that referenced this pull request Aug 1, 2017
* [Framework/Accessibility] Add kuiScreenReaderOnly class

* fix typo

* use GuideLink

* add screen_reader react component and tests

* export KuiScreenReaderOnly

* --wip-- [skip ci]

* fix lint rule

* remove obsolete snapshots
@tsullivan
Copy link
Member Author

6.x/6.1.0: 508d6cb

@tsullivan tsullivan deleted the enhance/framework-accessible-screenreaderonly branch August 1, 2017 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Project:Accessibility review Team:Platform-Design Team Label for Kibana Design Team. Support the Analyze group of plugins. v6.1.0 v7.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants