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

Initial version of a11y guide #13390

Merged
merged 9 commits into from
Aug 14, 2017
Merged

Initial version of a11y guide #13390

merged 9 commits into from
Aug 14, 2017

Conversation

timroes
Copy link
Contributor

@timroes timroes commented Aug 8, 2017

The first draft of the discussed a11y guidelines, that can be extended over time.

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.

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


## Interactive elements

### Use `<button>` and `<a>`
Copy link
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 also specify that the <a> tag needs an href attribute.

Copy link
Contributor

@cjcenizal cjcenizal Aug 9, 2017

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.


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.
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 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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@cjcenizal cjcenizal Aug 9, 2017

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.

* 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.
Copy link
Contributor

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.
Copy link
Contributor

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?


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

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".

@timroes
Copy link
Contributor Author

timroes commented Aug 9, 2017

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

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?

Copy link
Contributor Author

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?

Copy link
Contributor

@cjcenizal cjcenizal Aug 9, 2017

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.

Copy link
Contributor Author

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.

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.

Sorry, I found a bunch of other really nitpicky things! 😄


### Use `<button>` and `<a>`

**TL;DR** *Use `<button>` and `<a>` (with `hred`) instead of click listeners on other elements
Copy link
Contributor

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


## Interactive elements

### Use `<button>` and `<a>`
Copy link
Contributor

@cjcenizal cjcenizal Aug 9, 2017

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.

**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.
Copy link
Contributor

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>?

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

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.


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="#"`
Copy link
Contributor

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=#.

Copy link
Contributor Author

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 😓


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.
Copy link
Contributor

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.


*Why not use other elements?*

If you create e.g. a *div* with a click listener (like `<div ng-click="ctrl.doSomething()">...</div>`)
Copy link
Contributor

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>?

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

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>?

@timroes
Copy link
Contributor Author

timroes commented Aug 11, 2017

Added some role information, and created the "Naming elements" section. Would appreciate another round of feedback :-)

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.

I found a couple last little things that can be fixed before merging, but overall this looks great man!!! 🍰

visual text representation (e.g. an icon button):

```html
<button aria-label="Add filter"><i class="fa fa-plus"></i></button>
Copy link
Contributor

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?

Copy link
Contributor

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?

Copy link
Contributor

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).


```html
<div id="datepicker">Date Picker</div>
<button aria-labelledby="datepicker"><i class="fa fa-calendar"></i></button>
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here.

#### `<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
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: therefor -> therefore

Copy link
Contributor Author

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.

@timroes timroes merged commit 99f1c65 into elastic:master Aug 14, 2017
@timroes timroes deleted the a11y-guide branch August 14, 2017 05:42
timroes added a commit that referenced this pull request Aug 14, 2017
* 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
@timroes
Copy link
Contributor Author

timroes commented Aug 14, 2017

Backport:

Sign up for free to 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.

3 participants