Skip to content

Commit f2c15ce

Browse files
erikkroesdaKmoR
authored andcommitted
fix(button): make JAWS/IE11 work with inner button
1 parent 3c7f5ab commit f2c15ce

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

packages/button/src/LionButton.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@ export class LionButton extends DisabledWithTabIndexMixin(SlotMixin(LitElement))
2222
return html`
2323
<div class="btn">
2424
${this._renderBefore()}
25-
<slot></slot>
25+
${this.constructor.__isIE11()
26+
? html`
27+
<div id="${this._buttonId}"><slot></slot></div>
28+
`
29+
: html`
30+
<slot></slot>
31+
`}
2632
${this._renderAfter()}
2733
<slot name="_button"></slot>
2834
<div class="click-area"></div>
@@ -132,6 +138,13 @@ export class LionButton extends DisabledWithTabIndexMixin(SlotMixin(LitElement))
132138
this.type = 'submit';
133139
this.active = false;
134140
this.__setupDelegationInConstructor();
141+
142+
if (this.constructor.__isIE11()) {
143+
this._buttonId = `button-${Math.random()
144+
.toString(36)
145+
.substr(2, 10)}`;
146+
this.setAttribute('aria-labelledby', this._buttonId);
147+
}
135148
}
136149

137150
connectedCallback() {
@@ -234,4 +247,10 @@ export class LionButton extends DisabledWithTabIndexMixin(SlotMixin(LitElement))
234247
__isKeyboardClickEvent(e) {
235248
return e.keyCode === 32 /* space */ || e.keyCode === 13 /* enter */;
236249
}
250+
251+
static __isIE11() {
252+
const ua = window.navigator.userAgent;
253+
const result = /Trident/.test(ua);
254+
return result;
255+
}
237256
}

packages/button/test/lion-button.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
keyDownOn,
1010
keyUpOn,
1111
} from '@polymer/iron-test-helpers/mock-interactions.js';
12+
import { LionButton } from '../src/LionButton.js';
1213

1314
import '../lion-button.js';
1415

@@ -20,6 +21,16 @@ function getTopElement(el) {
2021
return crossBrowserRoot.elementFromPoint(left + width / 2, top + height / 2);
2122
}
2223

24+
let originalIsIE11Method;
25+
function mockIsIE11() {
26+
originalIsIE11Method = LionButton.__isIE11;
27+
LionButton.__isIE11 = () => true;
28+
}
29+
30+
function restoreMockIsIE11() {
31+
LionButton.__isIE11 = originalIsIE11Method;
32+
}
33+
2334
describe('lion-button', () => {
2435
it('behaves like native `button` in terms of a11y', async () => {
2536
const el = await fixture(`<lion-button>foo</lion-button>`);
@@ -198,6 +209,18 @@ describe('lion-button', () => {
198209
await el.updateComplete;
199210
expect(el.getAttribute('tabindex')).to.equal('5');
200211
});
212+
213+
it('has an aria-labelledby and wrapper element in IE11', async () => {
214+
mockIsIE11();
215+
const el = await fixture(`<lion-button>foo</lion-button>`);
216+
expect(el.hasAttribute('aria-labelledby')).to.be.true;
217+
const wrapperId = el.getAttribute('aria-labelledby');
218+
expect(el.shadowRoot.querySelector(`#${wrapperId}`)).to.exist;
219+
expect(el.shadowRoot.querySelector(`#${wrapperId}`)).dom.to.equal(
220+
`<div id="${wrapperId}"><slot></slot></div>`,
221+
);
222+
restoreMockIsIE11();
223+
});
201224
});
202225

203226
describe('form integration', () => {

0 commit comments

Comments
 (0)