Material-ui: [Grid] Failed prop type: The property `xs` of `Grid` must be used on `item`

Created on 16 Feb 2019  路  9Comments  路  Source: mui-org/material-ui

  • [X] This is not a v0.x issue.
  • [X] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 馃


Shouldn't throw a warning.

Current Behavior 馃槸


Throws a warning when page is reloaded, complaining about xs being set on a non-item grid tag, when the line throwing the warning doesn't have it.

Steps to Reproduce 馃暪


Link:

  1. Load the page at https://codesandbox.io/s/010p1j4o0l
  2. Once it's loaded, hit the Reload icon on the internal browser (the one on the page, displaying the results. Not your own browser)
    3.
    4.

Context 馃敠


The functionality seems to be correct regardless of the warning, but I'm wondering if this could have some more serious ramifications later on. I also HATE warnings ;)

Your Environment 馃寧

| Tech | Version |
|--------------|---------|
| Material-UI | v3.9.1 |
| React | v16.7.0 |
| Browser | Chrome 72.0 |
| TypeScript | No |
| etc. | |

Grid docs good first issue

Most helpful comment

@sgermain06 You should set the item={true} property as the warning is suggesting.

All 9 comments

@sgermain06 You should set the item={true} property as the warning is suggesting.

Oh. I got it. Thanks!

It does give me the same warning even after doing this.

<Grid container xs={12}>
    <Grid item={true} xs={8} sm={10}></Grid>
</Grid>

@chilupa xs is only available on flex items, a flex container doesn't allow it.

This warning is quire misleading. I had to Google why I'm getting it. Maybe if "must" was replaced with "can only".

@bmakan What do you think about this diff?

Before
Capture d鈥檈虂cran 2020-11-18 a虁 12 43 16

After
Capture d鈥檈虂cran 2020-11-18 a虁 12 45 56

diff --git a/packages/material-ui-utils/src/requirePropFactory.js b/packages/material-ui-utils/src/requirePropFactory.js
index 4d6707aab1..8292921adb 100644
--- a/packages/material-ui-utils/src/requirePropFactory.js
+++ b/packages/material-ui-utils/src/requirePropFactory.js
@@ -15,7 +15,7 @@ export default function requirePropFactory(componentNameInError) {
     if (typeof props[propName] !== 'undefined' && !props[requiredProp]) {
       return new Error(
         `The prop \`${propFullNameSafe}\` of ` +
-          `\`${componentNameInError}\` must be used on \`${requiredProp}\`.`,
+          `\`${componentNameInError}\` can only be used together with \`${requiredProp}\`.`,
       );
     }

@oliviertassinari I think it's much better. It's harder to judge it now when I know what it means. Maybe adding word "prop" at the end might make it even more obvious?

The prop ${propFullNameSafe} of ${componentNameInError} can only be used together with the ${requiredProp} prop.

I think item is a very generic term in programming and can cause confusion by itself when it shows up.

@bmakan Sounds great, do you want to work on a pull request? :)

@oliviertassinari Can I create a PR for this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

activatedgeek picture activatedgeek  路  3Comments

ryanflorence picture ryanflorence  路  3Comments

ghost picture ghost  路  3Comments

reflog picture reflog  路  3Comments

ericraffin picture ericraffin  路  3Comments