Skip to content

Commit

Permalink
Don't set read-only class if readonly is null
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cincodenada committed May 27, 2021
1 parent 1919593 commit 18244ed
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions addon/mixins/checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
}
},

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 18244ed

Please sign in to comment.