fix(form-core): set aria-disabled next to the disabled attribute for NVDA screen reader

This commit is contained in:
gerjanvangeest 2024-02-07 16:25:04 +01:00 committed by Thijs Louisse
parent 059b018793
commit 19256d31bf
3 changed files with 24 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/ui': patch
---
[form-core]: set aria-disabled next to the disabled attribute for NVDA screen reader

View file

@ -276,6 +276,10 @@ const FormControlMixinImplementation = superclass =>
updated(changedProperties) {
super.updated(changedProperties);
if (changedProperties.has('disabled')) {
this._inputNode?.setAttribute('aria-disabled', this.disabled.toString());
}
if (changedProperties.has('_ariaLabelledNodes')) {
this.__reflectAriaAttr(
'aria-labelledby',

View file

@ -198,6 +198,21 @@ describe('FormControlMixin', () => {
expect(descriptionIdsBefore).to.equal(descriptionIdsAfter);
});
it('sets aria-disabled on inputNode based on disabled property', async () => {
const el = /** @type {FormControlMixinClass} */ (
await fixture(html`
<${tag}>${inputSlot}</${tag}>
`)
);
const { _inputNode } = getFormControlMembers(el);
expect(_inputNode.hasAttribute('aria-disabled')).to.be.true;
expect(_inputNode.getAttribute('aria-disabled')).to.equal('false');
el.disabled = true;
expect(_inputNode.getAttribute('aria-disabled')).to.equal('false');
});
it('clicking the label should call `_onLabelClick`', async () => {
const spy = sinon.spy();
const el = /** @type {FormControlMixinClass} */ (