Material-ui: [CardTitle] Unwanted warnings on CardTitle with actAsExpander

Created on 21 Jul 2016  路  9Comments  路  Source: mui-org/material-ui

Problem description

When using CardTitle as a card expander I get this React warning in the console:

Warning: Unknown props `actAsExpander`, `showExpandableButton` on <div> tag. Remove these props from the element. For details, see https://fb.me/react-unknown-prop
    in div (created by CardTitle)
    in CardTitle

And also on expandable CardText:

Warning.js:44 Warning: Unknown prop `expandable` on <div> tag. Remove this prop from the element. For details, see https://fb.me/react-unknown-prop
    in div (created by CardText)
    in CardText

It works just fine though.

Steps to reproduce

<Card>
  <CardTitle
    title='...'
    actAsExpander
    showExpandableButton
  />
  <CardText expandable>
  </CardText>
</Card>

Versions

bug 馃悰 Card

All 9 comments

I'm having this issue as well. Very annoying as we are trying to stomp out all react warnings.

Same here ! material ui 0.15.2, chromium 51.0.2704.79, react 0.15.2

I'm using a temporary fix that seems to be working for the time being. To fix the error on CardText, for instance, open node_modules/material-ui/Card/CardText.js.

Change line 59 from this:

_extends({}, this.props, { style: prepareStyles(rootStyle) }),

to this:

_extends({}, { style: prepareStyles(rootStyle) }),

Would you do a PR with that ?

EDIT: well, it actually doesn't really solve the problem, it's really temporary indeed

From React documentation:
However, React currently strips all unknown attributes, so specifying them in your React app will not cause them to be rendered.

So it should throw the warning but the custom attribute shouldn't get into the DOM during production mode.

@arunkarottu: Removing the this.props not only gets rid of the custom DOM attributes but all of the valid DOM attributes except for the styles as well, which you might want to inject. As I see it, Material UI uses the property on the JS side but then we are injecting all props into the DOM, which is indeed not needed.

A better temporary solution would be a tempObject, get rid of the Key since it isnt't doing anything and pass the tempObject to the DOM.

I'll get into this tomorrow.

okay, this did the job for me:

function omit(currentProps) {
    var propsCopy = Object.assign({}, currentProps);
    if (propsCopy.expandable != undefined){delete propsCopy.expandable;}
    return propsCopy;
}

and

_extends({}, omit(this.props), { style: prepareStyles(rootStyle) }),

this solution still is kind of ugly but it is less intrusive

It's just a solution to remove the warnings, and we have to do it manually for each props, i did that in CardTitle :

function omit(currentProps) {
  var propsCopy = Object.assign({}, currentProps);
  ['actAsExpander', 'showExpandableButton'].forEach(p => {
    delete propsCopy[p]
  })
  return propsCopy;
}

Still, it would be great to have a true fix

this problem is linked to #4594 as well.

That issue should have been fixed by #4675 and #4603. Thanks for the help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

revskill10 picture revskill10  路  3Comments

finaiized picture finaiized  路  3Comments

mb-copart picture mb-copart  路  3Comments

reflog picture reflog  路  3Comments

rbozan picture rbozan  路  3Comments