Skip to content

Commit

Permalink
Merge pull request #58 from mike-north/more-tests
Browse files Browse the repository at this point in the history
Clickable action support applied broadly
  • Loading branch information
mike-north committed Aug 26, 2015
2 parents 3918c9c + 24bb70a commit dc7ea7c
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
3 changes: 2 additions & 1 deletion addon/components/-base-toggle-component.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import Ember from 'ember';
import BaseToplevelComponent from './-base-toplevel-component';
import RippleSupport from '../mixins/ripple-support';
import ClickActionSupport from '../mixins/click-action-support';
import layout from '../templates/components/mdl-checkbox';

const { computed } = Ember;

export default BaseToplevelComponent.extend(RippleSupport, {
export default BaseToplevelComponent.extend(RippleSupport, ClickActionSupport, {
tagName: 'label',
layout,
value: false,
Expand Down
3 changes: 2 additions & 1 deletion addon/components/mdl-nav-item.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Ember from 'ember';
import ChildComponentSupport from 'ember-composability/mixins/child-component-support';
import ClickActionSupport from '../mixins/click-action-support';
import MdlNav from './mdl-nav';

export default Ember.Component.extend(ChildComponentSupport, {
export default Ember.Component.extend(ChildComponentSupport, ClickActionSupport, {
_parentComponentTypes: Ember.A([MdlNav]),
inDrawer: true,
inHeader: true
Expand Down
10 changes: 9 additions & 1 deletion addon/components/mdl-radio.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import Ember from 'ember';
import BaseToggleComponent from './-base-toggle-component';
import layout from '../templates/components/mdl-radio';

const { computed, computed: { oneWay } } = Ember;

export default BaseToggleComponent.extend({
primaryClassName: 'radio',
layout,
checked: false,
name: oneWay('_defaultName'),

didInsertElement() {
this._super(...arguments);
let mdlradio = new window.MaterialRadio(this.get('element'));
this.element.MaterialRadio = mdlradio;
this.set('_mdlComponent', mdlradio);
}
},

_defaultName: computed('elementId', function() {
return `${this.get('elementId')}-name`;
})
});
2 changes: 1 addition & 1 deletion addon/templates/components/mdl-radio.hbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<input type="radio" id={{_inputId}} class="mdl-radio__button" name="options" value={{value}} disabled={{disabled}} checked={{checked}} />
<input type="radio" id={{_inputId}} class="mdl-radio__button" name={{name}} value={{value}} disabled={{disabled}} checked={{checked}} />
<span class="mdl-radio__label">{{label}}{{yield}}</span>
25 changes: 25 additions & 0 deletions tests/integration/components/mdl-button-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,28 @@ test('fires action "action" on click by default', function(assert) {
this.$('.mdl-button').click();
});

test('does not fire action when disabled', function(assert) {
assert.expect(2);
// Set any properties with this.set('myProperty', 'value');
// Handle any actions with this.on('myAction', function(val) { ... });
let clickCount = 0;
this.on('buttonClicked', val => {
clickCount++;
});

this.set('buttonDisabled', false);

this.render(hbs`
{{#mdl-button action='buttonClicked' class='this-is-my-button' disabled=buttonDisabled}}
Hello
{{/mdl-button}}
`);

this.$('.mdl-button').click();
assert.equal(clickCount, 1, 'One click action fired');

this.set('buttonDisabled', true);
this.$('.mdl-button').click();

assert.equal(clickCount, 1, 'Still one click');
});

0 comments on commit dc7ea7c

Please sign in to comment.