fix dialog aria-expand attribute
This commit is contained in:
parent
5f92a722e6
commit
719991fdd3
4 changed files with 39 additions and 12 deletions
5
.changeset/olive-mirrors-grab.md
Normal file
5
.changeset/olive-mirrors-grab.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@lion/ui': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
add "aria-expanded" attribute only for the non-modal dialogs
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/* eslint-disable lit-a11y/no-autofocus */
|
/* eslint-disable lit-a11y/no-autofocus */
|
||||||
import { expect, fixture as _fixture, html, unsafeStatic } from '@open-wc/testing';
|
import { expect, fixture as _fixture, html, unsafeStatic, aTimeout } from '@open-wc/testing';
|
||||||
import { runOverlayMixinSuite } from '../../overlays/test-suites/OverlayMixin.suite.js';
|
import { runOverlayMixinSuite } from '../../overlays/test-suites/OverlayMixin.suite.js';
|
||||||
import '@lion/ui/define/lion-dialog.js';
|
import '@lion/ui/define/lion-dialog.js';
|
||||||
|
|
||||||
|
|
@ -166,4 +166,24 @@ describe('lion-dialog', () => {
|
||||||
el.setAttribute('opened', '');
|
el.setAttribute('opened', '');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Accessibility', () => {
|
||||||
|
it('adds [aria-expanded] to invoker button', async () => {
|
||||||
|
const el = await fixture(
|
||||||
|
html` <lion-dialog>
|
||||||
|
<div slot="content" class="dialog">Hey there</div>
|
||||||
|
<button slot="invoker">Popup button</button>
|
||||||
|
</lion-dialog>`,
|
||||||
|
);
|
||||||
|
const invokerButton = /** @type {HTMLElement} */ (el.querySelector('[slot="invoker"]'));
|
||||||
|
|
||||||
|
expect(invokerButton.getAttribute('aria-expanded')).to.equal(null);
|
||||||
|
await invokerButton.click();
|
||||||
|
await aTimeout(0);
|
||||||
|
expect(invokerButton.getAttribute('aria-expanded')).to.equal(null);
|
||||||
|
await invokerButton.click();
|
||||||
|
await aTimeout(0);
|
||||||
|
expect(invokerButton.getAttribute('aria-expanded')).to.equal(null);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -495,11 +495,11 @@ describe('<lion-input-datepicker>', () => {
|
||||||
const el = await fixture(html`<lion-input-datepicker></lion-input-datepicker>`);
|
const el = await fixture(html`<lion-input-datepicker></lion-input-datepicker>`);
|
||||||
const elObj = new DatepickerInputObject(el);
|
const elObj = new DatepickerInputObject(el);
|
||||||
|
|
||||||
expect(elObj.invokerEl.getAttribute('aria-expanded')).to.equal('false');
|
expect(elObj.invokerEl.getAttribute('aria-expanded')).to.equal(null);
|
||||||
await elObj.openCalendar();
|
await elObj.openCalendar();
|
||||||
expect(elObj.invokerEl.getAttribute('aria-expanded')).to.equal('true');
|
expect(elObj.invokerEl.getAttribute('aria-expanded')).to.equal(null);
|
||||||
await elObj.closeCalendar();
|
await elObj.closeCalendar();
|
||||||
expect(elObj.invokerEl.getAttribute('aria-expanded')).to.equal('false');
|
expect(elObj.invokerEl.getAttribute('aria-expanded')).to.equal(null);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('is accessible when closed', async () => {
|
it('is accessible when closed', async () => {
|
||||||
|
|
|
||||||
|
|
@ -640,13 +640,14 @@ export class OverlayController extends EventTarget {
|
||||||
__setupTeardownAccessibility({ phase }) {
|
__setupTeardownAccessibility({ phase }) {
|
||||||
if (phase === 'init') {
|
if (phase === 'init') {
|
||||||
this.__storeOriginalAttrs(this.contentNode, ['role', 'id']);
|
this.__storeOriginalAttrs(this.contentNode, ['role', 'id']);
|
||||||
|
const isModal = this.hasBackdrop;
|
||||||
|
|
||||||
if (this.invokerNode) {
|
if (this.invokerNode) {
|
||||||
this.__storeOriginalAttrs(this.invokerNode, [
|
const attributesToStore = ['aria-labelledby', 'aria-describedby'];
|
||||||
'aria-expanded',
|
if (!isModal) {
|
||||||
'aria-labelledby',
|
attributesToStore.push('aria-expanded');
|
||||||
'aria-describedby',
|
}
|
||||||
]);
|
this.__storeOriginalAttrs(this.invokerNode, attributesToStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.contentNode.id) {
|
if (!this.contentNode.id) {
|
||||||
|
|
@ -661,7 +662,7 @@ export class OverlayController extends EventTarget {
|
||||||
}
|
}
|
||||||
this.contentNode.setAttribute('role', 'tooltip');
|
this.contentNode.setAttribute('role', 'tooltip');
|
||||||
} else {
|
} else {
|
||||||
if (this.invokerNode) {
|
if (this.invokerNode && !isModal) {
|
||||||
this.invokerNode.setAttribute('aria-expanded', `${this.isShown}`);
|
this.invokerNode.setAttribute('aria-expanded', `${this.isShown}`);
|
||||||
}
|
}
|
||||||
if (!this.contentNode.getAttribute('role')) {
|
if (!this.contentNode.getAttribute('role')) {
|
||||||
|
|
@ -1092,7 +1093,7 @@ export class OverlayController extends EventTarget {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.__wrappingDialogNode.close();
|
this.__wrappingDialogNode.close();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
this.__wrappingDialogNode.showModal();
|
this.__wrappingDialogNode.show();
|
||||||
}
|
}
|
||||||
// else {
|
// else {
|
||||||
this.enableTrapsKeyboardFocus();
|
this.enableTrapsKeyboardFocus();
|
||||||
|
|
@ -1299,7 +1300,8 @@ export class OverlayController extends EventTarget {
|
||||||
if (phase === 'init' || phase === 'teardown') {
|
if (phase === 'init' || phase === 'teardown') {
|
||||||
this.__setupTeardownAccessibility({ phase });
|
this.__setupTeardownAccessibility({ phase });
|
||||||
}
|
}
|
||||||
if (this.invokerNode && !this.isTooltip) {
|
const isModal = this.hasBackdrop;
|
||||||
|
if (this.invokerNode && !this.isTooltip && !isModal) {
|
||||||
this.invokerNode.setAttribute('aria-expanded', `${phase === 'show'}`);
|
this.invokerNode.setAttribute('aria-expanded', `${phase === 'show'}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue