Skip to content

Commit 137bbef

Browse files
Merge pull request #2798 from ing-bank/fix/implement-readonly-on-label-click
Fix toggleable readonly switch on label click
2 parents 57099be + f159668 commit 137bbef

4 files changed

Lines changed: 14 additions & 2 deletions

File tree

.changeset/fifty-corners-juggle.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@lion/ui': patch
3+
---
4+
5+
Fixes toggleable readonly switch on label click

packages/ui/components/form-core/src/choice-group/ChoiceInputMixin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ const ChoiceInputMixinImplementation = superclass =>
238238
*/
239239
// eslint-disable-next-line no-unused-vars
240240
_toggleChecked(ev) {
241-
if (this.disabled) {
241+
if (this.disabled || this.readOnly) {
242242
return;
243243
}
244244
this._isHandlingUserInput = true;

packages/ui/components/switch/src/LionSwitch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ export class LionSwitch extends ScopedElementsMixin(ChoiceInputMixin(LionField))
148148
* @protected
149149
*/
150150
_onLabelClick() {
151-
if (this.disabled) {
151+
if (this.disabled || this.readOnly) {
152152
return;
153153
}
154154
this._inputNode.focus();

packages/ui/components/switch/test/lion-switch.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ describe('lion-switch', () => {
7272
expect(isActiveElement(_inputNode)).to.be.false;
7373
});
7474

75+
it('clicking the label should not toggle the checked state when readonly', async () => {
76+
const el = await fixture(html`<lion-switch readonly label="Enable Setting"></lion-switch>`);
77+
const { _labelNode } = getFormControlMembers(el);
78+
_labelNode.click();
79+
expect(el.checked).to.be.false;
80+
});
81+
7582
it('should sync its "disabled" state to child button', async () => {
7683
const el = await fixture(html`<lion-switch disabled></lion-switch>`);
7784
const { _inputNode } = getSwitchMembers(el);

0 commit comments

Comments
 (0)