From 438ee0013d72f7b9710bc1548ed52841a70b4948 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Tue, 26 Jun 2018 00:13:00 +0200 Subject: [PATCH] [Dialog] Add a scroll property --- packages/material-ui/src/Dialog/Dialog.d.ts | 5 +++ packages/material-ui/src/Dialog/Dialog.js | 46 +++++++++++++++++---- packages/material-ui/src/Modal/Modal.js | 5 +-- pages/api/dialog.md | 5 +++ 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/packages/material-ui/src/Dialog/Dialog.d.ts b/packages/material-ui/src/Dialog/Dialog.d.ts index 2fb6ec362b2adf..416749422c0dc2 100644 --- a/packages/material-ui/src/Dialog/Dialog.d.ts +++ b/packages/material-ui/src/Dialog/Dialog.d.ts @@ -11,6 +11,7 @@ export interface DialogProps fullWidth?: boolean; maxWidth?: 'xs' | 'sm' | 'md' | false; PaperProps?: Partial; + scroll?: 'body' | 'paper'; TransitionComponent?: React.ReactType; transitionDuration?: TransitionProps['timeout']; TransitionProps?: TransitionProps; @@ -18,7 +19,11 @@ export interface DialogProps export type DialogClassKey = | 'root' + | 'scrollPaper' + | 'scrollBody' | 'paper' + | 'paperScrollPaper' + | 'paperScrollBody' | 'paperWidthXs' | 'paperWidthSm' | 'paperWidthMd' diff --git a/packages/material-ui/src/Dialog/Dialog.js b/packages/material-ui/src/Dialog/Dialog.js index 08259edec4949d..eed3745a96a89d 100644 --- a/packages/material-ui/src/Dialog/Dialog.js +++ b/packages/material-ui/src/Dialog/Dialog.js @@ -11,29 +11,55 @@ import { duration } from '../styles/transitions'; import Paper from '../Paper'; export const styles = theme => ({ - root: { + root: {}, + scrollPaper: { + display: 'flex', justifyContent: 'center', alignItems: 'center', }, + scrollBody: { + overflowY: 'auto', + overflowX: 'hidden', + }, paper: { display: 'flex', - margin: theme.spacing.unit * 4, - maxHeight: `calc(100% - ${theme.spacing.unit * 8}px)`, flexDirection: 'column', - flex: '0 1 auto', + margin: 48, position: 'relative', overflowY: 'auto', // Fix IE11 issue, to remove at some point. // We disable the focus ring for mouse, touch and keyboard users. outline: 'none', }, + paperScrollPaper: { + flex: '0 1 auto', + maxHeight: `calc(100% - ${48 * 2}px)`, + }, + paperScrollBody: { + margin: '48px auto', + }, paperWidthXs: { maxWidth: Math.max(theme.breakpoints.values.xs, 360), + '&$paperScrollBody': { + [theme.breakpoints.down(Math.max(theme.breakpoints.values.xs, 360) + 48 * 2)]: { + margin: 48, + }, + }, }, paperWidthSm: { maxWidth: theme.breakpoints.values.sm, + '&$paperScrollBody': { + [theme.breakpoints.down(theme.breakpoints.values.sm + 48 * 2)]: { + margin: 48, + }, + }, }, paperWidthMd: { maxWidth: theme.breakpoints.values.md, + '&$paperScrollBody': { + [theme.breakpoints.down(theme.breakpoints.values.md + 48 * 2)]: { + margin: 48, + }, + }, }, paperFullWidth: { width: '100%', @@ -43,7 +69,7 @@ export const styles = theme => ({ width: '100%', maxWidth: '100%', height: '100%', - maxHeight: '100%', + maxHeight: 'none', borderRadius: 0, }, }); @@ -73,6 +99,7 @@ function Dialog(props) { onExiting, open, PaperProps, + scroll, TransitionComponent, transitionDuration, TransitionProps, @@ -81,7 +108,7 @@ function Dialog(props) { return ( ({ root: { - display: 'flex', - width: '100%', - height: '100%', position: 'fixed', zIndex: theme.zIndex.modal, + right: 0, + bottom: 0, top: 0, left: 0, }, diff --git a/pages/api/dialog.md b/pages/api/dialog.md index f97e612a6eae52..a40b5db36f9561 100644 --- a/pages/api/dialog.md +++ b/pages/api/dialog.md @@ -33,6 +33,7 @@ Dialogs are overlaid modal paper based components with a backdrop. | onExiting | func |   | Callback fired when the dialog is exiting. | | open * | bool |   | If `true`, the Dialog is open. | | PaperProps | object |   | Properties applied to the `Paper` element. | +| scroll | enum: 'body' |
 'paper'
| 'paper' | Determine the container for scrolling the dialog. | | TransitionComponent | union: string |
 func |
 object
| Fade | Transition component. | | transitionDuration | union: number |
 {enter?: number, exit?: number}
| { enter: duration.enteringScreen, exit: duration.leavingScreen } | The duration for the transition, in milliseconds. You may specify a single timeout for all transitions, or individually with an object. | | TransitionProps | object |   | Properties applied to the `Transition` element. | @@ -44,7 +45,11 @@ Any other properties supplied will be spread to the root element ([Modal](/api/m You can override all the class names injected by Material-UI thanks to the `classes` property. This property accepts the following keys: - `root` +- `scrollPaper` +- `scrollBody` - `paper` +- `paperScrollPaper` +- `paperScrollBody` - `paperWidthXs` - `paperWidthSm` - `paperWidthMd`