chore(combobox): clicking label focuses toggle button
This commit is contained in:
parent
0dc706b6f9
commit
d4dcb7c1fb
3 changed files with 28 additions and 0 deletions
5
.changeset/famous-wolves-notice.md
Normal file
5
.changeset/famous-wolves-notice.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@lion/switch': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
**switch**: clicking label focuses button
|
||||||
|
|
@ -130,4 +130,15 @@ export class LionSwitch extends ScopedElementsMixin(ChoiceInputMixin(LionField))
|
||||||
_syncButtonSwitch() {
|
_syncButtonSwitch() {
|
||||||
this._inputNode.disabled = this.disabled;
|
this._inputNode.disabled = this.disabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @configure FormControlMixin
|
||||||
|
* @protected
|
||||||
|
*/
|
||||||
|
_onLabelClick() {
|
||||||
|
if (this.disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._inputNode.focus();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,18 @@ describe('lion-switch', () => {
|
||||||
expect(el.checked).to.be.false;
|
expect(el.checked).to.be.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('clicking the label should focus the toggle button', async () => {
|
||||||
|
const el = await fixture(html`<lion-switch label="Enable Setting"></lion-switch>`);
|
||||||
|
el._labelNode.click();
|
||||||
|
expect(document.activeElement).to.equal(el._inputNode);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clicking the label should not focus the toggle button when disabled', async () => {
|
||||||
|
const el = await fixture(html`<lion-switch disabled label="Enable Setting"></lion-switch>`);
|
||||||
|
el._labelNode.click();
|
||||||
|
expect(document.activeElement).to.not.equal(el._inputNode);
|
||||||
|
});
|
||||||
|
|
||||||
it('should sync its "disabled" state to child button', async () => {
|
it('should sync its "disabled" state to child button', async () => {
|
||||||
const el = await fixture(html`<lion-switch disabled></lion-switch>`);
|
const el = await fixture(html`<lion-switch disabled></lion-switch>`);
|
||||||
const { inputNode } = getProtectedMembers(el);
|
const { inputNode } = getProtectedMembers(el);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue