Adds radio-button proxy component called radio-button-composer. Ember radio button only passes along radio value to container component, the proxy bind the name of the radio target, effectively providng two arguments, and also ensures the requried components of name, groupValue and value are passed along on instantiation

This commit is contained in:
Seyi Adebajo 2017-03-24 21:41:45 -07:00 committed by Mars Lan
parent 543716c624
commit 25c3524ead
2 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,34 @@
import Ember from 'ember';
const {
Component,
get
} = Ember;
export default Component.extend({
tagName: '',
didReceiveAttrs() {
this._super(...arguments);
const attrs = this.attrs;
['name', 'groupValue', 'value'].forEach(attr => {
if (!(attr in attrs)) {
throw new Error(
`Attribute '${attr}' is required to be passed in when instantiating this component.`
);
}
});
},
actions: {
changed() {
const closureAction = get(this, 'attrs.changed');
if (typeof closureAction === 'function') {
return closureAction(...arguments);
}
this.sendAction('changed', ...arguments);
}
}
});

View File

@ -0,0 +1,11 @@
{{#radio-button
value=value
groupValue=groupValue
required=required
disabled=disabled
name=name
radioId=radioId
radioClass=radioClass
changed=(action "changed" name)}}
{{yield}}
{{/radio-button}}