-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Framework/Accessibility] Add kuiScreenReaderOnly class #13133
Conversation
There was a problem hiding this 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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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'> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
834c1fc
to
b731aec
Compare
b731aec
to
940b27e
Compare
@cjcenizal I've added the component and the test. This is ready for re-review |
There was a problem hiding this 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?
There was a problem hiding this 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.
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. |
* [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
6.x/6.1.0: 508d6cb |
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](https://user-images.githubusercontent.com/908371/28644533-cf160c86-720e-11e7-95ce-a3a5f7dae814.gif)