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

fix(Modal): RemoveScroll is overriding Modal's div's ref #2697

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
3 changes: 1 addition & 2 deletions packages/core/src/components/Modal/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,13 @@ const Modal = forwardRef(
style={zIndexStyle}
/>
<FocusLockComponent returnFocus>
<RemoveScroll forwardProps>
<RemoveScroll forwardProps ref={ref}>
<motion.div
variants={modalAnimationVariants}
initial="exit"
animate="enter"
exit="exit"
custom={anchorElementRef}
ref={ref}
className={cx(
styles.modal,
getStyle(styles, camelCase("size-" + size)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ describe("Modal", () => {
expect(getByText("My content")).toBeInTheDocument();
});

it("ensures the ref prop does not return null when modal is shown", () => {
const ref = React.createRef<HTMLDivElement>();

const { getByTestId } = render(
<Modal id={id} show ref={ref} data-testid="modal">
<div>Content</div>
</Modal>
);

expect(getByTestId("modal")).toBeInTheDocument();
expect(ref.current).not.toBeNull();
});

it("applies default size as 'medium' when not supplied with a size", () => {
const { getByRole } = render(
<Modal id={id} show>
Expand Down
Loading