Skip to content

Commit

Permalink
Fixed checkbox toggle
Browse files Browse the repository at this point in the history
The ember classes were clobbered
  • Loading branch information
Ilya Radchenko committed Oct 10, 2014
1 parent 7fcec7f commit 9da8e79
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
11 changes: 8 additions & 3 deletions app/components/x-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ export default Ember.Component.extend({
on: 'On',
toggled: false,

inputClasses: Ember.computed('themeClass', function () {
inputClasses: Ember.observer('themeClass', 'inputCheckbox', function () {
var themeClass = this.get('themeClass');
var input = this.get('inputCheckbox');

return ['x-toggle', themeClass];
}),
if (input) {
var inputClasses = input.get('classNames') || [];

input.set('classNames', inputClasses.concat(['x-toggle', themeClass]));
}
}).on('init'),

themeClass: Ember.computed('theme', function () {
var theme = this.get('theme') || 'default';
Expand Down
2 changes: 1 addition & 1 deletion app/templates/components/x-toggle.hbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{input classNames=inputClasses id=generatedId type='checkbox' checked=toggled}}
{{input id=generatedId type='checkbox' checked=toggled viewName='inputCheckbox'}}
<label class='x-toggle-btn' {{bind-attr for=generatedId data-tg-off=off data-tg-on=on}}></label>
9 changes: 9 additions & 0 deletions tests/dummy/app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Ember from 'ember';

export default Ember.Controller.extend({
actions: {
checkboxToggled: function () {
this.toggleProperty('toggled');
}
}
});

0 comments on commit 9da8e79

Please sign in to comment.