Skip to content

Commit

Permalink
fix: πŸ› make only dialog body scroll
Browse files Browse the repository at this point in the history
Used `position: sticky` to make the title and actions sections stay in
place while the body scrolls

βœ… Closes: #17
  • Loading branch information
Cody Rose committed Mar 5, 2021
1 parent 4c01409 commit 60beb7b
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/components/SQFormDialog/SQFormDialogInner.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Slide,
makeStyles
} from '@material-ui/core';
import {useTheme} from '@material-ui/core/styles';
import {Form} from 'formik';
import {RoundedButton, DialogAlert, useDialog} from 'scplus-shared-components';
import {useSQFormContext} from '../../index';
Expand All @@ -19,12 +20,28 @@ const Transition = React.forwardRef((props, ref) => {
return <Slide direction="down" ref={ref} {...props} />;
});

const stickyStyles = {
position: 'sticky',
background: ({palette}) => palette.background.paper,
zIndex: 1
};

const useTitleStyles = makeStyles({
root: {
...stickyStyles,
top: 0,
borderBottom: ({palette}) => `1px solid ${palette.divider}`
}
});
const useActionsStyles = makeStyles({
root: {
display: 'flex',
justifyContent: 'space-between',
flex: '1 1 100%',
padding: '16px 24px'
padding: '16px 24px',
...stickyStyles,
bottom: 0,
borderTop: ({palette}) => `1px solid ${palette.divider}`
}
});

Expand All @@ -42,7 +59,9 @@ function SQFormDialogInner({
title,
muiGridProps
}) {
const actionsClasses = useActionsStyles();
const theme = useTheme();
const titleClasses = useTitleStyles(theme);
const actionsClasses = useActionsStyles(theme);
const {resetForm, dirty: isDirty} = useSQFormContext();

const [
Expand Down Expand Up @@ -74,10 +93,10 @@ function SQFormDialogInner({
onClose={handleCancel}
>
<Form>
<DialogTitle disableTypography={true}>
<DialogTitle disableTypography={true} classes={titleClasses}>
<Typography variant="h4">{title}</Typography>
</DialogTitle>
<DialogContent dividers={true}>
<DialogContent>
<Grid
{...muiGridProps}
container
Expand Down

0 comments on commit 60beb7b

Please sign in to comment.