Skip to content

Commit

Permalink
fix(Modal): RemoveScroll is overriding Modal's div's ref
Browse files Browse the repository at this point in the history
  • Loading branch information
YossiSaadi committed Jan 1, 2025
1 parent 428ba51 commit 1b30fa5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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
13 changes: 13 additions & 0 deletions packages/core/src/components/Modal/Modal/__tests__/Modal.test.tsx
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

0 comments on commit 1b30fa5

Please sign in to comment.