Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResponsiveContainer does not support fix height such as 200px #62

Closed
lrrfantasy opened this issue Mar 25, 2016 · 2 comments
Closed

ResponsiveContainer does not support fix height such as 200px #62

lrrfantasy opened this issue Mar 25, 2016 · 2 comments

Comments

@lrrfantasy
Copy link

<ResponsiveContainer height={200}>
  <PieChart>
    {...}
  </PieChart>
</ResponsiveContainer>

This works nicely but React reports warning of
Invalid prop 'height' of type 'number' supplied to 'ResponsiveContainer', expected 'string'

If I change the height to <ResponsiveContainer height='200'> the container doesn't work.

I looked at the source code of ResponsiveContainer.js, the propType does require string. However the function it depends on in DataUtils.js, here is the core:

export const getPercentValue = (percent, totalValue, defaultValue = 0, validate = false) => {
  // ...
  const str = percent.toString();
  const index = str.indexOf('%');
  let value;

  if (index > 0) {
    value = totalValue * parseFloat(str.slice(0, index)) / 100;
  } else if (percent === +percent) {
    value = percent;
  }

Apparently my height '200' in string doesn't go into any of if branch so this function gives me a height of 0, but 200 in number works well.

Is there a way supporting 200px of height, and without propType warning?
Either a fix in getPercentValue or a change of propType would work for me.

@xile611
Copy link
Member

xile611 commented Mar 25, 2016

Thanks. This problem was fixed in v0.8.8.

Initially I think that the width and height must be a percentage. But you may need to set the width to be a percentage, but the height to be a fixed value. So the width and height of ResponsiveContainer can be a percentage or a fixed number in v0.8.8.

@xile611 xile611 closed this as completed Mar 25, 2016
@lrrfantasy
Copy link
Author

Nice work. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants