Skip to content

Commit da4f150

Browse files
authored
Merge pull request #28 from RalucaNicola/master
Add button accessibility
2 parents aaa883a + e6b1141 commit da4f150

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

packages/wired-button/wired-button.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ export class WiredButton extends LitElement {
1313
super();
1414
this.elevation = 1;
1515
this.disabled = false;
16-
1716
}
1817

1918
_createRoot() {
20-
const root = this.attachShadow({ mode: 'open', delegatesFocus: true });
19+
const root = this.attachShadow({ mode: 'open' });
2120
this.classList.add('pending');
2221
return root;
2322
}
@@ -41,24 +40,23 @@ export class WiredButton extends LitElement {
4140
flex-direction: column;
4241
text-align: center;
4342
display: inline-flex;
44-
outline: none;
4543
}
46-
44+
4745
:host(.pending) {
4846
opacity: 0;
4947
}
50-
48+
5149
:host(:active) path {
5250
transform: scale(0.97) translate(1.5%, 1.5%);
5351
}
54-
52+
5553
:host(.disabled) {
5654
opacity: 0.6 !important;
5755
background: rgba(0, 0, 0, 0.07);
5856
cursor: default;
5957
pointer-events: none;
6058
}
61-
59+
6260
.overlay {
6361
position: absolute;
6462
top: 0;
@@ -67,11 +65,11 @@ export class WiredButton extends LitElement {
6765
bottom: 0;
6866
pointer-events: none;
6967
}
70-
68+
7169
svg {
7270
display: block;
7371
}
74-
72+
7573
path {
7674
stroke: currentColor;
7775
stroke-width: 0.7;
@@ -103,6 +101,14 @@ export class WiredButton extends LitElement {
103101
connectedCallback() {
104102
super.connectedCallback();
105103
setTimeout(() => this._didRender());
104+
this.addEventListener('keydown', (event) => {
105+
if ((event.keyCode === 13) || (event.keyCode === 32)) {
106+
event.preventDefault();
107+
this.click();
108+
}
109+
});
110+
this.setAttribute('role', 'button');
111+
this.setAttribute('aria-label', this.innerHTML);
106112
}
107113

108114
_didRender() {
@@ -122,6 +128,8 @@ export class WiredButton extends LitElement {
122128
(wired.line(svg, s.width + (i * 2), s.height + (i * 2), s.width + (i * 2), i * 2)).style.opacity = (75 - (i * 10)) / 100;
123129
}
124130
this.classList.remove('pending');
131+
132+
this.tabIndex = this.disabled ? -1 : (this.getAttribute('tabindex') || 0);
125133
}
126134
}
127135

0 commit comments

Comments
 (0)