fix(switch): do not change checked state when disabled

This commit is contained in:
Jose Luis de Vega 2022-09-14 18:55:28 +02:00 committed by GitHub
parent 650657231a
commit d838ea100c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'@lion/switch': patch
---
fix(LionSwitchButton): do not dispatch checked-change event when is disabled

View file

@ -158,7 +158,7 @@ export class LionSwitchButton extends DisabledWithTabIndexMixin(LitElement) {
*/
requestUpdate(name, oldValue) {
super.requestUpdate(name, oldValue);
if (this.isConnected && name === 'checked' && this.checked !== oldValue) {
if (this.isConnected && name === 'checked' && this.checked !== oldValue && !this.disabled) {
this.__checkedStateChange();
}
}

View file

@ -118,6 +118,14 @@ describe('lion-switch-button', () => {
expect(handlerSpy.called).to.be.false;
});
it('should not dispatch "checked-changed" event if disabled on update', () => {
const handlerSpy = sinon.spy();
el.disabled = true;
el.addEventListener('checked-changed', handlerSpy);
el.checked = !el.checked;
expect(handlerSpy.called).to.be.false;
});
describe('a11y', () => {
it('should manage "aria-checked"', async () => {
expect(el.hasAttribute('aria-checked')).to.be.true;