-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
Conversation
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(); | ||
} | ||
}); | ||
} |
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.
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> |
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 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')
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.
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);
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.
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.
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.
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
.
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.
Seems like it doesn't work for me even when delegateFocus
is false
.
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.
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); | |||
} |
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.
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
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 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> |
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.
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> |
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.
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);
done @pshihn :) I also removed the I tried it out with the example by setting different tabindex, disabling the button and played around with voiceover. |
Thanks a lot @RalucaNicola I learned something about accessibility going through this with you. |
thanks a lot for your help, I hope I can do the next components all by myself :) |
@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:
aria-label
, so I added it in the_didRender
method, because there I had access to the innerHTML.keydown
event listener in the constructor?Thank you!