Skip to content

Commit

Permalink
🐛 fix: Refactor Modal component to handle dynamic content height
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin3go committed Dec 25, 2023
1 parent 614a0b6 commit 5b79dfd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/Modal/demos/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export default () => {
Open Modal
</Button>
<Modal onCancel={handleCancel} onOk={handleOk} open={isModalOpen} title="Basic Modal">
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
{Array.from({ length: 20 }).map((_, index) => (
<p key={index}>Some contents...</p>
))}

Check warning on line 28 in src/Modal/demos/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/Modal/demos/index.tsx#L26-L28

Added lines #L26 - L28 were not covered by tests
</Modal>
</>
);
Expand Down
12 changes: 8 additions & 4 deletions src/Modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { memo } from 'react';
import ActionIcon from '@/ActionIcon';
import Icon from '@/Icon';

const useStyles = createStyles(({ css, token, prefixCls }) => ({
const useStyles = createStyles(({ css, token, prefixCls }, props: { maxHeight: string }) => ({

Check warning on line 10 in src/Modal/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/Modal/index.tsx#L10

Added line #L10 was not covered by tests
content: css`
.${prefixCls}-modal-body {
overflow: hidden;
overflow: scroll;
max-height: ${props.maxHeight};

Check warning on line 14 in src/Modal/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/Modal/index.tsx#L13-L14

Added lines #L13 - L14 were not covered by tests
padding: 0 16px 16px;
}
.${prefixCls}-modal-footer {
Expand Down Expand Up @@ -38,7 +39,9 @@ const useStyles = createStyles(({ css, token, prefixCls }) => ({
`,
}));

export type ModalProps = AntModalProps;
export type ModalProps = AntModalProps & {
maxHeight?: string;
};

Check warning on line 44 in src/Modal/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/Modal/index.tsx#L42-L44

Added lines #L42 - L44 were not covered by tests

const Modal = memo<ModalProps>(
({
Expand All @@ -50,10 +53,11 @@ const Modal = memo<ModalProps>(
onCancel,
open,
destroyOnClose,
maxHeight = 'calc(70vh - 108px)', // or none; 108px = header + footer height;

Check warning on line 56 in src/Modal/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/Modal/index.tsx#L56

Added line #L56 was not covered by tests
...rest
}) => {
const { mobile } = useResponsive();
const { styles, cx, theme } = useStyles();
const { styles, cx, theme } = useStyles({ maxHeight });

Check warning on line 60 in src/Modal/index.tsx

View check run for this annotation

Codecov / codecov/patch

src/Modal/index.tsx#L60

Added line #L60 was not covered by tests

if (mobile)
return (
Expand Down

0 comments on commit 5b79dfd

Please sign in to comment.