diff --git a/packages/button/src/LionButton.js b/packages/button/src/LionButton.js index 8f9449163..a694dc2f8 100644 --- a/packages/button/src/LionButton.js +++ b/packages/button/src/LionButton.js @@ -173,7 +173,11 @@ export class LionButton extends DisabledWithTabIndexMixin(SlotMixin(LitElement)) this._buttonId = `button-${Math.random().toString(36).substr(2, 10)}`; if (browserDetection.isIE11) { - this.updateComplete.then(() => this.setAttribute('aria-labelledby', this._buttonId)); + this.updateComplete.then(() => { + if (!this.hasAttribute('aria-labelledby')) { + this.setAttribute('aria-labelledby', this._buttonId); + } + }); } } diff --git a/packages/button/test/lion-button.test.js b/packages/button/test/lion-button.test.js index bd340c2ca..123e7569d 100644 --- a/packages/button/test/lion-button.test.js +++ b/packages/button/test/lion-button.test.js @@ -211,6 +211,15 @@ describe('lion-button', () => { browserDetectionStub.restore(); }); + it('does not override aria-labelledby when provided by user', async () => { + const browserDetectionStub = sinon.stub(browserDetection, 'isIE11').value(true); + const el = /** @type {LionButton} */ (await fixture( + `foo`, + )); + expect(el.getAttribute('aria-labelledby')).to.equal('some-id another-id'); + browserDetectionStub.restore(); + }); + it('has a native button node with aria-hidden set to true', async () => { const el = /** @type {LionButton} */ (await fixture('')); @@ -239,9 +248,9 @@ describe('lion-button', () => { foo `); - const button = /** @type {LionButton} */ ( - /** @type {LionButton} */ (form.querySelector('lion-button')) - ); + const button /** @type {LionButton} */ = /** @type {LionButton} */ (form.querySelector( + 'lion-button', + )); button.click(); expect(formSubmitSpy).to.have.been.calledOnce; }); @@ -253,9 +262,9 @@ describe('lion-button', () => { foo `); - const button = /** @type {LionButton} */ ( - /** @type {LionButton} */ (form.querySelector('lion-button')) - ); + const button /** @type {LionButton} */ = /** @type {LionButton} */ (form.querySelector( + 'lion-button', + )); button.dispatchEvent(new KeyboardEvent('keyup', { key: ' ' })); await aTimeout(0); await aTimeout(0); @@ -286,9 +295,9 @@ describe('lion-button', () => { reset `); - const btn = /** @type {LionButton} */ ( - /** @type {LionButton} */ (form.querySelector('lion-button')) - ); + const btn /** @type {LionButton} */ = /** @type {LionButton} */ (form.querySelector( + 'lion-button', + )); const firstName = /** @type {HTMLInputElement} */ (form.querySelector( 'input[name=firstName]', )); @@ -350,9 +359,9 @@ describe('lion-button', () => { `); - /** @type {LionButton} */ (form.querySelector('lion-button')).dispatchEvent( - new KeyboardEvent('keyup', { key: ' ' }), - ); + /** @type {LionButton} */ form + .querySelector('lion-button') + .dispatchEvent(new KeyboardEvent('keyup', { key: ' ' })); await aTimeout(0); await aTimeout(0); @@ -410,7 +419,7 @@ describe('lion-button', () => { it('is fired once', async () => { const clickSpy = /** @type {EventListener} */ (sinon.spy()); const el = /** @type {LionButton} */ (await fixture( - html`foo`, + html` foo `, )); el.click(); @@ -425,9 +434,11 @@ describe('lion-button', () => { it('is fired one inside a form', async () => { const formClickSpy = /** @type {EventListener} */ (sinon.spy(e => e.preventDefault())); const el = /** @type {HTMLFormElement} */ (await fixture( - html`
- foo -
`, + html` +
+ foo +
+ `, )); // @ts-ignore