preact-material-components icon indicating copy to clipboard operation
preact-material-components copied to clipboard

Extend `mdcProps`

Open prateekbh opened this issue 7 years ago • 4 comments

We should extend mdcProps to either take in Strings as it does today or take objectsto accommodate non-boolean values as well. as shown in #261. This will allow simplify code for child components and we can use it later for DOM cleanup as suggested by @filoozom

prateekbh avatar Sep 19 '17 05:09 prateekbh

@filoozom help me understand will this also cover #240 ?

prateekbh avatar Sep 19 '17 12:09 prateekbh

Well, depends on the implementation. If _mdcProps can take an object that says something like:

{
  type: String, // defaults to Boolean
  required: true, // defaults to false
  addToParent: false // defaults to true
}

Then yes. The thing is that MaterialComponent shouldn't just add all _mdcProps to the element returned by materialDom(), because some props are used on other elements. TextField is a good example for that. Let's say we had:

constructor() {
  this._mdcProps = {
    src: {
      type: String,
      required: true,
      addToParent: false
    }
  };
}

materialDom({ src }) {
  return (
    <div class="some-class">
      <img src={src} />
    </div>
  );
}

And then src should be removed from the element but src should not be added to the div.

filoozom avatar Sep 19 '17 14:09 filoozom

I'm interested in this issue but I'm not sure I understand it 100%

Do you mean some fields in _mdcProps that will determine which props are added to which element?

wuweiweiwu avatar Mar 07 '18 00:03 wuweiweiwu

This could be interesting for 2.0

cromefire avatar Sep 29 '18 11:09 cromefire