Skip to content

Commit

Permalink
fix: disables label action on disabled component (#111)
Browse files Browse the repository at this point in the history
* Update component.js

* Adds tests for disabled labels
  • Loading branch information
ntgussoni authored and knownasilya committed Apr 2, 2018
1 parent d2b3ad1 commit 471575a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
5 changes: 3 additions & 2 deletions addon/components/x-toggle/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export default Component.extend({
actions: {
sendToggle(value) {
let onToggle = this.get('onToggle');

if (value !== this.get('value') && typeof onToggle === 'function') {
let disabled = this.get('disabled');

if (!disabled && (value !== this.get('value')) && (typeof onToggle === 'function')) {
onToggle(value);

// The click on input/label will toggle the input unconditionally.
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/components/x-toggle/component-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,27 @@ test('clicking component labels triggers onToggle action', function(assert) {
assert.equal(this.get('value'), false, 'clicking off label again, value stays false');
});

test('clicking disabled component labels does not trigger onToggle action', function(assert) {
this.set('value', false);
this.set('disabled', true);
this.set('onToggle', val => {
this.set('value', val);
});

this.render(hbs`{{x-toggle
value=value
showLabels=true
onToggle=(action onToggle)
disabled=disabled
}}`);

this.$('.on-label').click();
assert.equal(this.get('value'), false, 'clicking on label does not change the value');

this.$('.off-label').click();
assert.equal(this.get('value'), false, 'clicking off label does not change the value');
});

if (emberVersionGTE(2, 0)) {
test('clicking component works with bespoke values and mut helper', function(assert) {
this.set('value', false);
Expand Down

0 comments on commit 471575a

Please sign in to comment.