From 80e04d4e67a5640873f49a13acc9b7728d5f253a Mon Sep 17 00:00:00 2001 From: Joel Bradshaw Date: Wed, 26 May 2021 17:59:29 -0700 Subject: [PATCH] Don't set read-only class if readonly is null toggleClass() requires a boolean value, not just a truthy/falsy one. When readonly is null, the current code results in the read-only class being toggled (since null is treated the same as the argument not being provided), resutling in indeterminate results depending on what the previous value of readonly was. To avoid this surprising behavior, just coerce the value of readonly to a boolean before passing it to toggleClass(), so that null will always result in no read-only class, same as if the readonly attribute was not provided. --- addon/mixins/checkbox.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addon/mixins/checkbox.js b/addon/mixins/checkbox.js index 39fc84c5c..5538b854c 100644 --- a/addon/mixins/checkbox.js +++ b/addon/mixins/checkbox.js @@ -20,7 +20,7 @@ var CheckboxMixin = Ember.Mixin.create(Base, { settings.onChange = this.get('_onChange'); } if (this._hasOwnProperty(this.attrs, 'readonly') || this.get('readonly') != null) { - this.$().toggleClass('read-only', this.get('readonly')); + this.$().toggleClass('read-only', Boolean(this.get('readonly'))); } }, @@ -83,7 +83,7 @@ var CheckboxMixin = Ember.Mixin.create(Base, { // Handle readonly if (attrName === 'readonly') { // We need to add a class verses updating the property, since semantic is caching the value internall - return this.$().toggleClass('read-only', attrValue); + return this.$().toggleClass('read-only', Boolean(attrValue)); } // Default return this._super(...arguments);