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

[Container] Add disableGutters prop #15872

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/pages/api/container.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ You can learn more about the difference by [reading this guide](/guides/minimizi
| <span class="prop-name required">children&nbsp;*</span> | <span class="prop-type">node</span> | | |
| <span class="prop-name">classes</span> | <span class="prop-type">object</span> | | Override or extend the styles applied to the component. See [CSS API](#css) below for more details. |
| <span class="prop-name">component</span> | <span class="prop-type">elementType</span> | <span class="prop-default">'div'</span> | The component used for the root node. Either a string to use a DOM element or a component. |
| <span class="prop-name">disableGutters</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | If `true`, the left and right padding is removed. |
| <span class="prop-name">fixed</span> | <span class="prop-type">bool</span> | <span class="prop-default">false</span> | Set the max-width to match the min-width of the current breakpoint. This is useful if you'd prefer to design for a fixed set of sizes instead of trying to accommodate a fully fluid viewport. It's fluid by default. |
| <span class="prop-name">maxWidth</span> | <span class="prop-type">'xs'<br>&#124;&nbsp;'sm'<br>&#124;&nbsp;'md'<br>&#124;&nbsp;'lg'<br>&#124;&nbsp;'xl'<br>&#124;&nbsp;false</span> | <span class="prop-default">'lg'</span> | Determine the max-width of the container. The container width grows with the size of the screen. Set to `false` to disable `maxWidth`. |

Expand All @@ -42,6 +43,7 @@ Any other props supplied will be provided to the root element (native element).
| Rule name | Global class | Description |
|:-----|:-------------|:------------|
| <span class="prop-name">root</span> | <span class="prop-name">.MuiContainer-root</span> | Styles applied to the root element.
| <span class="prop-name">disableGutters</span> | <span class="prop-name">.MuiContainer-disableGutters</span> | Styles applied to the root element if `disableGutters={true}`.
| <span class="prop-name">fixed</span> | <span class="prop-name">.MuiContainer-fixed</span> | Styles applied to the root element if `fixed={true}`.
| <span class="prop-name">maxWidthXs</span> | <span class="prop-name">.MuiContainer-maxWidthXs</span> | Styles applied to the root element if `maxWidth="xs"`.
| <span class="prop-name">maxWidthSm</span> | <span class="prop-name">.MuiContainer-maxWidthSm</span> | Styles applied to the root element if `maxWidth="sm"`.
Expand Down
2 changes: 2 additions & 0 deletions packages/material-ui/src/Container/Container.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { StandardProps } from '..';
export interface ContainerProps
extends StandardProps<React.HTMLAttributes<HTMLDivElement>, ContainerClassKey> {
component?: React.ElementType<React.HTMLAttributes<HTMLDivElement>>;
disableGutters?: boolean;
fixed?: boolean;
maxWidth?: 'xs' | 'sm' | 'md' | 'lg' | 'xl' | false;
}

export type ContainerClassKey =
| 'root'
| 'disableGutters'
| 'fixed'
| 'maxWidthXs'
| 'maxWidthSm'
Expand Down
11 changes: 11 additions & 0 deletions packages/material-ui/src/Container/Container.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export const styles = theme => ({
paddingRight: theme.spacing(4),
},
},
/* Styles applied to the root element if `disableGutters={true}`. */
disableGutters: {
paddingLeft: 0,
paddingRight: 0,
},
/* Styles applied to the root element if `fixed={true}`. */
fixed: Object.keys(theme.breakpoints.values).reduce((acc, breakpoint) => {
const value = theme.breakpoints.values[breakpoint];
Expand Down Expand Up @@ -70,6 +75,7 @@ const Container = React.forwardRef(function Container(props, ref) {
classes,
className,
component: Component = 'div',
disableGutters = false,
fixed = false,
maxWidth = 'lg',
...other
Expand All @@ -81,6 +87,7 @@ const Container = React.forwardRef(function Container(props, ref) {
classes.root,
{
[classes.fixed]: fixed,
[classes.disableGutters]: disableGutters,
[classes[`maxWidth${capitalize(String(maxWidth))}`]]: maxWidth !== false,
},
className,
Expand All @@ -107,6 +114,10 @@ Container.propTypes = {
* Either a string to use a DOM element or a component.
*/
component: PropTypes.elementType,
/**
* If `true`, the left and right padding is removed.
*/
disableGutters: PropTypes.bool,
/**
* Set the max-width to match the min-width of the current breakpoint.
* This is useful if you'd prefer to design for a fixed set of sizes
Expand Down