fix(switch): do not change checked state when disabled
This commit is contained in:
parent
650657231a
commit
d838ea100c
3 changed files with 14 additions and 1 deletions
5
.changeset/gentle-socks-juggle.md
Normal file
5
.changeset/gentle-socks-juggle.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@lion/switch': patch
|
||||
---
|
||||
|
||||
fix(LionSwitchButton): do not dispatch checked-change event when is disabled
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue