-
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
Initial version of a11y guide #13390
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.
Awesome! Had a few comments. Could you also migrate over the accessibility content from the HTML style guide: https://github.com/elastic/kibana/blob/master/style_guides/html_style_guide.md#accessibility
style_guides/accessibility_guide.md
Outdated
|
||
## Interactive elements | ||
|
||
### Use `<button>` and `<a>` |
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 think we should also specify that the <a>
tag needs an href
attribute.
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.
Can we change the title of this to "Use <button>
and <a href>
"? I think we should call out the importance of href as often as possible, because otherwise it will be very easy for people to think that just <a>
by itself is sufficient.
style_guides/accessibility_guide.md
Outdated
|
||
If you want to make an element clickable, use a `<button>` or `<a>` element for it. | ||
Use a *button* whenever it causes an action on the current page, and an *a* if it | ||
navigates to a different page. You can use click listeners just fine on these elements. |
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 use click listeners just fine on these elements.
I think we should advise using a click handler on button
only, and an href
with the anchor tag. If we use an anchor with a click handler, then we'll need to apply kbn-accessible-click
or KuiKeyboardAccessible
, because browsers won't trigger the click handler when you hit ENTER.
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.
This information also duplicates https://github.com/elastic/kibana/blob/master/style_guides/html_style_guide.md#prefer-button-and-a-when-making-interactive-elements-keyboard-accessible, so we should probably remove it from the HTML style guide.
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.
They trigger a click as long as the a
has an href
. So I guess this issue will collapse with the one above, about mentioning usage of href
. But I will try to make this more clear.
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.
Oh I see. I guess that raises the question, why would you want a click handler and an href?
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.
Isn't it non-semantic to use a link as a button? I think links should be used for navigating to different URLs, and buttons should be used for triggering event handlers. That way you know that you can open links in new windows or tabs, or just reference the URL it points to.
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 would totally agree with you in that. But I think there might be some cases, where the "navigation" is actually implemented in JS (like dynamically determine parts of the URL) in which this would be valid. That's why I left it in there.
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 agree, but if I understand correctly, here are the scenarios we can have:
<!-- Semantic -->
<a href="hardcoded/url">
<a href={dynamicUrl}>
<button onClick={doSomething}>
<button className="lookLikeALink" onClick={doSomething}>
<!-- Non-semantic -->
<a href onClick={doSomething}>
The last example is what I'm advocating against because it just doesn't make sense... you should just use a <button>
element styled to look like a link. The href is supposed to provide a hint of where you're going, and the anchor tag should allow you to open the href in a new tab, but none of that functionality is being used.
style_guides/accessibility_guide.md
Outdated
* You cannot focus it by pressing <kbd>tab</kbd>. You can add this behavior by | ||
adding `tabindex="0"` to the element. | ||
* You cannot trigger the click by pressing <kbd>Enter</kbd> or <kbd>Space</kbd>. | ||
We have a `kbn-accessible-click` directive for AngularJS to add that behavior. |
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.
And we have the analogous KuiKeyboardAccessible
React component.
|
||
Those kind of elements, require a special interaction model. A [code editor](https://github.com/elastic/kibana/pull/13339) | ||
could require an <kbd>Enter</kbd> keypress before starting editing mode, and | ||
could leave that mode on <kbd>Escape</kbd> again. |
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.
Should we mention using role="application"
here, and some reasons why?
style_guides/accessibility_guide.md
Outdated
|
||
If you place it on the `input` you will overwrite the implicit `textbox` or `searchbox` | ||
role, and as such confuse the user, since it loses it meaning as in input element. | ||
If you place it on the `form` element you will also overwrite it's role and |
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: "it's role" should be "its role".
Ready for another review :-) |
be a good `role` (also see below) for that element. It is meant for elements providing | ||
their own interaction schemes. | ||
|
||
## Roles |
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.
Should we add role=main
, section
tags and revisit role=application
here 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 am not sure if we can and should make this a complete developer guideline or just pointing out most common pitfalls. I fear if we start documenting role=main
, section
, etc. we would also need to start explaining aria-label
/aria-labelledby
and aria-describedby
, etc.?
Which way do you and @cjcenizal think we should go with this document for now?
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's a very ambiguous line between "complete guideline" and "common pitfalls" because it's so relative to the experience level of the developer. I think we might as well err on the side of comprehensiveness and describe those roles, as well as aria-label/aria-labelledby
and aria-describedby
. We can use #11837 (comment) for the latter.
To elaborate on my line of reasoning: if we try to keep the guide limited to common pitfalls, then we'll run into this same question over and over, so it seems more maintainable to side-step the question entirely.
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.
Yeah, I see your point there, and will add an explanation tomorrow.
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.
Sorry, I found a bunch of other really nitpicky things! 😄
style_guides/accessibility_guide.md
Outdated
|
||
### Use `<button>` and `<a>` | ||
|
||
**TL;DR** *Use `<button>` and `<a>` (with `hred`) instead of click listeners on other elements |
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: hred
should be href
style_guides/accessibility_guide.md
Outdated
|
||
## Interactive elements | ||
|
||
### Use `<button>` and `<a>` |
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.
Can we change the title of this to "Use <button>
and <a href>
"? I think we should call out the importance of href as often as possible, because otherwise it will be very easy for people to think that just <a>
by itself is sufficient.
style_guides/accessibility_guide.md
Outdated
**TL;DR** *Use `<button>` and `<a>` (with `hred`) instead of click listeners on other elements | ||
and style it whatever way you need.* | ||
|
||
If you want to make an element clickable, use a `<button>` or `<a>` element for it. |
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.
Can we also change this to <a href>
?
style_guides/accessibility_guide.md
Outdated
and style it whatever way you need.* | ||
|
||
If you want to make an element clickable, use a `<button>` or `<a>` element for it. | ||
Use a *button* whenever it causes an action on the current page, and an *a* if it |
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 think this can be slightly improved by consistently referencing these elements using codeblocks, e.g. <button>
and <a href>
instead of button and a.
style_guides/accessibility_guide.md
Outdated
|
||
An `a` element must have an `href` attribute, so that (a) it will be correctly perceived | ||
as a link by a screen reader and (b) that registered click listener will correctly | ||
trigger on pressing <kbd>Enter</kbd>. If you don't need it, make it `hred="#"` |
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: hred=#
should be href=#
.
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.
Holy cow, how often can I make the same mistake 😓
style_guides/accessibility_guide.md
Outdated
|
||
If you want to make an element clickable, use a `<button>` or `<a>` element for it. | ||
Use a *button* whenever it causes an action on the current page, and an *a* if it | ||
navigates to a different page. You can use click listeners just fine on these elements. |
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.
Isn't it non-semantic to use a link as a button? I think links should be used for navigating to different URLs, and buttons should be used for triggering event handlers. That way you know that you can open links in new windows or tabs, or just reference the URL it points to.
style_guides/accessibility_guide.md
Outdated
|
||
*Why not use other elements?* | ||
|
||
If you create e.g. a *div* with a click listener (like `<div ng-click="ctrl.doSomething()">...</div>`) |
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.
Can we change div to <div>
?
style_guides/accessibility_guide.md
Outdated
Use a *button* whenever it causes an action on the current page, and an *a* if it | ||
navigates to a different page. You can use click listeners just fine on these elements. | ||
|
||
An `a` element must have an `href` attribute, so that (a) it will be correctly perceived |
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.
Can we change a
to <a>
?
Added some role information, and created the "Naming elements" section. Would appreciate another round of feedback :-) |
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 found a couple last little things that can be fixed before merging, but overall this looks great man!!! 🍰
style_guides/accessibility_guide.md
Outdated
visual text representation (e.g. an icon button): | ||
|
||
```html | ||
<button aria-label="Add filter"><i class="fa fa-plus"></i></button> |
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.
Can we change <i>
to <span>
, which is more semantic?
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.
Does font awesome not use <i>
tags anymore?
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.
Font awesome will work on any inline tag, and possibly any block-level tag (haven't tested).
style_guides/accessibility_guide.md
Outdated
|
||
```html | ||
<div id="datepicker">Date Picker</div> | ||
<button aria-labelledby="datepicker"><i class="fa fa-calendar"></i></button> |
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.
Same here.
style_guides/accessibility_guide.md
Outdated
#### `<section>` | ||
|
||
The `<section>` element, can be used to mark a region on the page, so that it | ||
appears in the landmark navigation. The section element therefor needs to have |
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: therefor -> therefore
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.
Just wanted to sound archaic - no kidding, will fix it.
* Initial version of a11y guide * Move a11y content from HTML guide to a11y guide * Add PR feedback * Add PRs feedback * Add more roles * Refactor labeling elements section * Rename "labeling elements" -> "naming elements" * Use span instead of i for icon examples * Correct typo
Backport:
|
The first draft of the discussed a11y guidelines, that can be extended over time.