paulavery-mithril / mithril-mdl

Material Design Lite components via mithril.js
BSD 3-Clause "New" or "Revised" License
29 stars 7 forks source link

Radio toggle component #30

Open srenault opened 8 years ago

srenault commented 8 years ago

How do you specify the name property to the inner input ? And for value ?

More generally , I expect every parameters except special ones like ripple to be assigned to the input.

m(mdl.Radio, { id: 'radio1', value: '1', name: 'options', checked: true, ripple: true }, 'Radio button 1')
UhhhWaitWhat commented 8 years ago

Hmm, I think this is kind of tricky right now. At least to do it nicely. I guess we could extend baseMixin so we can specify a set of attributes which should be skipped (maybe also a way to explicitly define the allowed ones). This would allow to do something like:

function view(ctrl, srcAttribs) {
    let outerAttribs = {};
    let innerAttribs = {};

    callMixin(baseMixin({only: ['checked', 'name', 'value', 'id']}), srcAttribs, innerAttribs);
    callMixin(baseMixin({exclude: ['checked', 'name', 'value', 'id']}), srcAttribs, outerAttribs);
}

By default all attributes would be copied over. The exclude parameter would specify a set of parameters which will not be copied over (or parsed). The only parameter would specify a set of parameters which would be copied or parsed.

All parseable parameters could be exposed as mdl.baseParams, so we could do the following to handle all the defaults and then only id and class.

callMixin(baseMixin({only: baseParams.concat(['id', 'class'])});

I hope I understood your question correctly. Would what I proposed help you?