Merge pull request #450 from ing-bank/fix/aria-invalid

fix(select-rich): add aria-invalid when invalid
This commit is contained in:
gerjanvangeest 2019-12-23 11:15:45 +01:00 committed by GitHub
commit 9fb158ce02
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View file

@ -278,6 +278,11 @@ export class LionSelectRich extends OverlayMixin(
this._inputNode.getAttribute('aria-describedby'), this._inputNode.getAttribute('aria-describedby'),
); );
} }
if (changedProps.has('showsFeedbackFor')) {
// The ValidateMixin sets aria-invalid on the inputNode, but in this component we also need it on the invoker
this._invokerNode.setAttribute('aria-invalid', this._hasFeedbackVisibleFor('error'));
}
} }
} }

View file

@ -667,5 +667,31 @@ describe('lion-select-rich interactions', () => {
expect(oEl.getAttribute('aria-posinset')).to.equal(`${i + 1}`); expect(oEl.getAttribute('aria-posinset')).to.equal(`${i + 1}`);
}); });
}); });
it('sets [aria-invalid="true"] to "._invokerNode" when there is an error', async () => {
const el = await fixture(html`
<lion-select-rich .validators=${[new Required()]}>
<lion-options slot="input">
<lion-option .choiceValue=${null}>Please select a value</lion-option>
<lion-option .modelValue=${{ value: 10, checked: true }}>Item 1</lion-option>
</lion-options>
</lion-select-rich>
`);
const invokerNode = el._invokerNode;
const options = el.querySelectorAll('lion-option');
await el.feedbackComplete;
await el.updateComplete;
expect(invokerNode.getAttribute('aria-invalid')).to.equal('false');
options[0].checked = true;
await el.feedbackComplete;
await el.updateComplete;
expect(invokerNode.getAttribute('aria-invalid')).to.equal('true');
options[1].checked = true;
await el.feedbackComplete;
await el.updateComplete;
expect(invokerNode.getAttribute('aria-invalid')).to.equal('false');
});
}); });
}); });