material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[Grid] Extra width of container & scrollbar

Open vedant1811 opened this issue 9 years ago • 51 comments

The <Grid container> extends beyond its parent, with half of spacing size. I have marked the extra width in red, also setting spacing to zero fixes the problem.

mobile-padding

Here is a working example: https://codesandbox.io/s/Y8nzGm5W. Similar code with a zero spacing works as expected: https://codesandbox.io/s/NxvYxvQpL.

vedant1811 avatar Jul 19 '17 07:07 vedant1811

I have found the same issue on flexboxgrid. I think that it's a limitation of our negative margin solution that implements the spacing. I have checked out what bootstrap is doing, they don't have this spacing feature, so no issue on their end.

So you have 3 available workarounds:

  • Not using the spacing feature and implementing it on userland spacing={0}, we could make this the default behavior.
  • Adding a padding on the parent with, at least, the spacing value: https://codesandbox.io/s/WnpKlQ32n
    <div style={{ padding: 20 }}>
      <Grid container spacing={40}>
  • Adding overflow-x: hidden; on the parent.

I'm closing as I can't think of a better alternative. If someone has a better solution for the spacing feature, please raise your voice :).

oliviertassinari avatar Jul 19 '17 11:07 oliviertassinari

To me, it seems like spacing={0} should be the default behavior. At least until a better solution comes along, because it appears to be a bug with <Grid /> to first-time users of material-ui.

hboylan avatar Nov 01 '17 20:11 hboylan

@hboylan In the light of all those issues open for this limitation, I'm starting to wonder! I wish we had access to some API usage analytics 📈 .

oliviertassinari avatar Nov 01 '17 20:11 oliviertassinari

I have added the waiting for users upvotes tag. I'm not sure people would prefer having spacing={0}. So please upvote this issue if you are. We will prioritize our effort based on the number of upvotes.

oliviertassinari avatar Nov 04 '17 13:11 oliviertassinari

At least 8 duplicated issues is a strong signal. I will add a note about this limitation in the documentation.

oliviertassinari avatar Nov 04 '17 13:11 oliviertassinari

Just wondering: Are there any caveats using the 2nd workaround you described?

If not, you could add this in the Grid-container-Component per default?

update: => silly me ;) of course: we are loosing the space, sorry.

PutziSan avatar Nov 23 '17 12:11 PutziSan

I'm unable to fix this in material-ui@next using spacing={0} in the container, or any of the other two solutions including overflowing-x and such. Maybe i'm missing something?

dukuo avatar Nov 26 '17 17:11 dukuo

flexboxgrid (which @oliviertassinari mentioned having the same issues) has a fork that claims to have fixed it. https://github.com/kristoferjoseph/flexboxgrid/issues/144#issuecomment-321694572 I haven't dug into the code, but might be worth investigating to see if there's something we can use in Grid.

mbrookes avatar Nov 27 '17 00:11 mbrookes

Hi,

We recently started adopting this library for one of our projects.

You can imagine our surprise when we found out this thread.

Basically this is a bug that's closed with no workarounds as of the latest material-next version. This is worrying. Even more worrying is the idea that instead of fixing this bug, we now have text added in the docs talking about "a limitation".

Do you guys have any procedures regarding bugs and bugfixes? Or is everything decided on the spot?


This is the 1.0.0-prerelease: https://github.com/mui-org/material-ui/issues?q=is%3Aopen+is%3Aissue+milestone%3Av1.0.0-prerelease

Extrapolating from this thread, shall we assume 1.0.0-prerelease actually has lots more bugs than what we see there? (i.e. this issue for example)

How many valid material-ui bugs did you guys close so far on github, and instead of fixing you added text in the docs?

Otherwise the framework is great. It's the procedures that are a bit worrying.

Thank you, and I apologise if I offended anyone and/or if I came a bit strong.

kmlx avatar Nov 30 '17 11:11 kmlx

@kmlx

shall we assume 1.0.0-~~prerelease~~beta actually has lots more bugs than what we see there?

You certainly should (see: Issues). And you should expect 1.0.0-rc.x to have bugs too, but the API will be mostly stable.

The timing of @ryanflorence's tweet is perfect.

I apologise if I offended anyone and/or if I came a bit strong.

If you know you're coming across a bit strong, don't apologize; rethink what it is you want to say, and how you want to say it. (And perhaps take a look at how much value you've got out of open source, vs. how much you've contributed, and decide if your complaint carries any weight.)

Better still, if the workarounds provided in the docs aren't sufficient, get stuck in to the CSS and see if you can resolve the limitation that's bothering you.

mbrookes avatar Nov 30 '17 13:11 mbrookes

@mbrookes

Thank you for taking the time to reply.

You certainly should (see: Issues). And you should expect 1.0.0-rc.x to have bugs too, but the API will be mostly stable.

Glad to hear the API will be mostly stable. As any project, I assume there will be various undiscovered issues.

Still, at the moment the workarounds for this issue are not working and the issue itself is closed. As per your previous message, this flexboxgrid fork might provide a solution. I shall assume the commits starting from Aug 1st are the ones where one should be looking for a fix.

kmlx avatar Dec 01 '17 12:12 kmlx

If the documented workarounds are no longer working, (I'm on mobile currently, so not able to test), then this issue needs to be reopened.

Thanks for looking into a fix.

mbrookes avatar Dec 01 '17 17:12 mbrookes

I'm not having the issue btw, and my solution was to manually do spacing={0} in each <Grid container /> or <Grid item container /> component in my code.

dukuo avatar Dec 01 '17 18:12 dukuo

@kmlx I have successfully tested the suggested workarounds with beta.22. Feel free to report back if you find a permanent solution.

mbrookes avatar Dec 01 '17 20:12 mbrookes

I added spacing={0} but actually wanted spacing, so I added padding, and made it only add the padding above the medium breakpoint where it showed two columns:

const styles = theme => ({
  dividerRight: {
    [theme.breakpoints.up('md')]: {
      paddingRight: theme.spacing.unit * 0.5
    }
  },
  dividerLeft: {
    [theme.breakpoints.up('md')]: {
      paddingLeft: theme.spacing.unit * 0.5
    }
  },
});

Then I added className={classes.dividerRight} to the left column (since the divider is on the right) and className={classes.dividerLeft} to the right column

benatkin avatar Mar 09 '18 02:03 benatkin

Just had this issue. Solved it with adding the following css to grid's container and it's looking good

.grid-container {
  width: 100% !important;
  margin: 0 !important;
}

martjoao avatar Jun 19 '18 00:06 martjoao

@martjoao For me this resulted in unwanted padding around the outside of my grid container (I have elements inside that should be flush with the edges).

My quick and dirty solution to this was to just throw overflow-x: hidden; on the body element. But on certain browsers (mobile ones in particular) when you scroll the horizontal scrollbar flashes for a second, indicating to the user they can scroll right. This is still undesirable for me.


EDIT:

Just saw the the overflow approach was mentioned above. My bad.

saricden avatar Jul 15 '18 21:07 saricden

I think it's worth noting that the intended usage of <Grid> is not application/primary layout (e.g. app bar, side bar, content area etc). It's really intended for distributing content elements in a grid (e.g. a list of profiles). With that in mind, spacing elements with margins so that their content area is not affected - so you can e.g. add a background color or borders - makes sense.

But the documentation suggests that the <Grid> element should be used for primary layout by having a whole section named "Layout" describing the usage of <Grid>.

Another reason many people find this counterintuitive is because all other UI frameworks provide a mechanism for doing primary layout (which would be considered the 80% case, @oliviertassinari), and laying out a grid of content items is a secondary concern.

wmadden avatar Jul 18 '18 12:07 wmadden

But the documentation suggests that the element should be used for primary layout by having a whole section named "Layout" describing the usage of .

@wmadden Why is using the layout wording makes you think it's about the app/primary layout?

Another reason many people find this counterintuitive

What's counterintuitive?

which would be considered the 80% case

I agree, we have: #10986 for that.

oliviertassinari avatar Jul 18 '18 12:07 oliviertassinari

@wmadden Why is using the layout wording makes you think it's about the app/primary layout?

It's in a top-level section called "layout", rather than just a component demo. And phrasing like this:

The grid creates visual consistency between layouts while allowing flexibility across a wide variety of designs. Material Design’s responsive UI is based on a 12-column grid layout.

made me assume that it was appropriate to use it for laying out my application - where the negative margin limitation becomes a problem fast.

Another reason many people find this counterintuitive

I meant people find it counterintuitive that the Grid component shouldn't be used for primary layout, since UI frameworks typically provide a layout solution for that purpose - and it's usually in a top-level documentation topic called "layout".

It's a common assumption in React that children will be contained by their parent. The <Grid>'s negative margin breaks that assumption by extending beyond the boundaries of its parent, which makes its behavior look like a bug to anyone who's not aware that it's by design.

wmadden avatar Jul 18 '18 14:07 wmadden