Skip to content

Commit

Permalink
Add overridable fullscreen prop for the modal
Browse files Browse the repository at this point in the history
  • Loading branch information
bakerac4 committed Jan 28, 2025
1 parent 9b8a262 commit 32088c7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
27 changes: 24 additions & 3 deletions app/src/core/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,35 @@ import { useTheme } from '@mui/material/styles';
import { DialogActions } from '@mui/material';

interface ResponsiveModalProps extends DialogProps {
/**
* Callback function to be called when the modal is closed
*
* @memberof ResponsiveModalProps
*/
onCloseCallback?: () => void;
/**
* Disables the close button on the modal
*
* @memberof ResponsiveModalProps
*/
closeDisabled?: boolean;
/**
* Action children to be rendered in the modal
*
* @memberof ResponsiveModalProps
*/
actionChildren?: DialogProps['children'];
/**
* Overrides the default fullscreen behavior of showing full screen based upon the theme breakpoints (md or less)
*
* @memberof ResponsiveModalProps
*/
fullScreen?: boolean;
}

export default function Modal({ children, onCloseCallback, closeDisabled, actionChildren, ...rest }: ResponsiveModalProps) {
export default function Modal({ children, onCloseCallback, closeDisabled, actionChildren, fullScreen, ...rest }: ResponsiveModalProps) {
const theme = useTheme();
const fullScreen = useMediaQuery(theme.breakpoints.down('md'));
const isFullScreen = fullScreen ?? useMediaQuery(theme.breakpoints.down('md'));

const onClose = () => {
if (!closeDisabled) {
Expand All @@ -23,7 +44,7 @@ export default function Modal({ children, onCloseCallback, closeDisabled, action
};

return (
<Dialog {...rest} fullScreen={fullScreen} onClose={onClose}>
<Dialog {...rest} fullScreen={isFullScreen} onClose={onClose}>
<DialogContent>{children}</DialogContent>
{actionChildren && <DialogActions>{actionChildren}</DialogActions>}
</Dialog>
Expand Down
24 changes: 22 additions & 2 deletions app/src/core/components/__tests__/Modal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Modal', () => {
expect(onCloseCallback).not.toHaveBeenCalled();
});

it('renders in fullScreen mode on small screens', () => {
it('renders in fullScreen mode on small screens by default', () => {
vi.mocked(useMediaQuery).mockReturnValue(true);

render(
Expand All @@ -64,7 +64,7 @@ describe('Modal', () => {
expect(document.querySelector('.MuiDialog-paperFullScreen')).toBeInTheDocument();
});

it('renders in normal mode on large screens', () => {
it('renders in normal mode on large screens by default', () => {
vi.mocked(useMediaQuery).mockReturnValue(false);

render(
Expand All @@ -75,4 +75,24 @@ describe('Modal', () => {

expect(document.querySelector('.MuiDialog-paperFullScreen')).not.toBeInTheDocument();
});

it('renders in fullScreen mode when fullScreen prop is passed in as true', () => {
render(
<Modal open fullScreen>
<div>Test Content</div>
</Modal>
);

expect(document.querySelector('.MuiDialog-paperFullScreen')).toBeInTheDocument();
});

it('does not render in fullScreen mode when fullScreen prop is passed in as false', () => {
render(
<Modal open fullScreen={false}>
<div>Test Content</div>
</Modal>
);

expect(document.querySelector('.MuiDialog-paperFullScreen')).not.toBeInTheDocument();
});
});

0 comments on commit 32088c7

Please sign in to comment.