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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button accessibility #28

Merged
merged 5 commits into from Jun 13, 2018
Merged

Add button accessibility #28

merged 5 commits into from Jun 13, 2018

Conversation

RalucaNicola
Copy link
Contributor

@pshihn here's a PR for making the wired-button accessible. Can you have a look? This was way more difficult than I thought 馃榿

I ran into several issues because I didn't really understand how to use lit-element:

  1. not sure where the accessibility attributes should actually go, I added them to the div in the shadow dom. I noticed that if I add them directly on the wired-button element they wouldn't have any effect.
  2. not sure how to get the innerHTML of the wired-button element to set it as aria-label, so I added it in the _didRender method, because there I had access to the innerHTML.
  3. is it ok if I add the keydown event listener in the constructor?

Thank you!

@pshihn
Copy link
Contributor

pshihn commented Jun 9, 2018

I've added a wiki page with details on setting up the dev environment. That would be useful: https://github.com/wiredjs/wired-elements/wiki/Dev-Environment

event.preventDefault();
this.click();
}
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of constructor, this should be done in connectedCallback method when using web components. I think connectedCallback method is already defined in this class. This code can move there.

@@ -80,12 +85,16 @@ export class WiredButton extends LitElement {
}
</style>
<slot></slot>
<div class="overlay">
<div class="overlay" tabIndex="${this._getIndex()}" role="button">
<svg id="svg"></svg>
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 the correct node to apply the 'role' here would be 'this'. In all wired-elememts, overlay SVG node is usually purely aesthetic. Another alternative would be we encapsulate the inside another span and add roles to the span. In this case, i think the root node is probably the best option.

So, in the connectedCallback, you can call this.setAttribute('role', 'button')

Copy link
Contributor

Choose a reason for hiding this comment

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

Tab index should also be set on 'this'.
It should probably be set in the _didRender method because that would be called when disable changes as well.
You also need to consider that the user may have overwritten the tabIndex

this.tabIndex = this.disabled ? -1 : (this.tabIndex || 0);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Somehow I can't manage to make it work if I set the tabIndex on the shadow host. I was reading about it here and it should work without problems: https://developers.google.com/web/fundamentals/accessibility/focus/using-tabindex but I can't manage to set the focus on the wired-button when using the tab key. I'll look a bit more into this. For now I changed the code in the _didRender method and I've set it on this. But if you try out the example.html file it's not really working when using tab.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I asked a colleague and it comes from setting delegateFocus to true. In the wired-button component there are no focusable elements, so it won't get the focus when setting tabIndex on the wired-button. @pshihn is there a need for setting it to true? Otherwise I'll set it to false.

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like it doesn't work for me even when delegateFocus is false.

Copy link
Contributor

Choose a reason for hiding this comment

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

Figured it out. you need to set the delegateFocus to false
and when setting the tabIndex, get the default value from the attribute rather than proeprty

this.tabIndex = this.disabled ? -1 : (this.getAttribute('tabindex') || 0);

@@ -122,6 +131,9 @@ export class WiredButton extends LitElement {
(wired.line(svg, s.width + (i * 2), s.height + (i * 2), s.width + (i * 2), i * 2)).style.opacity = (75 - (i * 10)) / 100;
}
this.classList.remove('pending');

const overlay = this.shadowRoot.querySelector('.overlay');
overlay.setAttribute('aria-label', this.innerHTML);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

As per my previous comments, in the case of button, the correct node would be this. (Probably not the case for other controls.)
Again in connectedCallback you scan set the 'aria-label' property.

- add keyboard events in connectedCallback
- set role and aria-label in connectedCallback
- set tabIndex in _didRender method
@RalucaNicola
Copy link
Contributor Author

RalucaNicola commented Jun 11, 2018

@pshihn great, thanks for helping me set up the dev environment, it works now 馃憤 I have a small issue with tabIndex, I wrote a comment on it here, I'm still trying to figure out what's going on.

Copy link
Contributor

@pshihn pshihn left a comment

Choose a reason for hiding this comment

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

I added a comment about tabIndex. Once that change is made, this should be good to go.

@@ -80,12 +85,16 @@ export class WiredButton extends LitElement {
}
</style>
<slot></slot>
<div class="overlay">
<div class="overlay" tabIndex="${this._getIndex()}" role="button">
<svg id="svg"></svg>
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like it doesn't work for me even when delegateFocus is false.

@@ -80,12 +85,16 @@ export class WiredButton extends LitElement {
}
</style>
<slot></slot>
<div class="overlay">
<div class="overlay" tabIndex="${this._getIndex()}" role="button">
<svg id="svg"></svg>
Copy link
Contributor

Choose a reason for hiding this comment

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

Figured it out. you need to set the delegateFocus to false
and when setting the tabIndex, get the default value from the attribute rather than proeprty

this.tabIndex = this.disabled ? -1 : (this.getAttribute('tabindex') || 0);

@RalucaNicola
Copy link
Contributor Author

RalucaNicola commented Jun 13, 2018

done @pshihn :) I also removed the outline: none in the css, so that focus is visible.

I tried it out with the example by setting different tabindex, disabling the button and played around with voiceover.

@pshihn
Copy link
Contributor

pshihn commented Jun 13, 2018

Thanks a lot @RalucaNicola I learned something about accessibility going through this with you.

@pshihn pshihn merged commit da4f150 into rough-stuff:master Jun 13, 2018
@RalucaNicola
Copy link
Contributor Author

thanks a lot for your help, I hope I can do the next components all by myself :)

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

Successfully merging this pull request may close these issues.

None yet

2 participants