Skip to content

Commit 18244ed

Browse files
committed
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.
1 parent 1919593 commit 18244ed

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

addon/mixins/checkbox.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var CheckboxMixin = Ember.Mixin.create(Base, {
2020
settings.onChange = this.get('_onChange');
2121
}
2222
if (this._hasOwnProperty(this.attrs, 'readonly') || this.get('readonly') != null) {
23-
this.$().toggleClass('read-only', this.get('readonly'));
23+
this.$().toggleClass('read-only', Boolean(this.get('readonly')));
2424
}
2525
},
2626

@@ -83,7 +83,7 @@ var CheckboxMixin = Ember.Mixin.create(Base, {
8383
// Handle readonly
8484
if (attrName === 'readonly') {
8585
// We need to add a class verses updating the property, since semantic is caching the value internall
86-
return this.$().toggleClass('read-only', attrValue);
86+
return this.$().toggleClass('read-only', Boolean(attrValue));
8787
}
8888
// Default
8989
return this._super(...arguments);

0 commit comments

Comments
 (0)