Skip to content

Commit 7f1772f

Browse files
authored
fix(Modal): RemoveScroll is overriding Modal's div's ref (#2697)
1 parent 08ddae3 commit 7f1772f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/core/src/components/Modal/Modal/Modal.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,13 @@ const Modal = forwardRef(
115115
style={zIndexStyle}
116116
/>
117117
<FocusLockComponent returnFocus>
118-
<RemoveScroll forwardProps>
118+
<RemoveScroll forwardProps ref={ref}>
119119
<motion.div
120120
variants={modalAnimationVariants}
121121
initial="exit"
122122
animate="enter"
123123
exit="exit"
124124
custom={anchorElementRef}
125-
ref={ref}
126125
className={cx(
127126
styles.modal,
128127
getStyle(styles, camelCase("size-" + size)),

packages/core/src/components/Modal/Modal/__tests__/Modal.test.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,19 @@ describe("Modal", () => {
6161
expect(getByText("My content")).toBeInTheDocument();
6262
});
6363

64+
it("ensures the ref prop does not return null when modal is shown", () => {
65+
const ref = React.createRef<HTMLDivElement>();
66+
67+
const { getByTestId } = render(
68+
<Modal id={id} show ref={ref} data-testid="modal">
69+
<div>Content</div>
70+
</Modal>
71+
);
72+
73+
expect(getByTestId("modal")).toBeInTheDocument();
74+
expect(ref.current).not.toBeNull();
75+
});
76+
6477
it("applies default size as 'medium' when not supplied with a size", () => {
6578
const { getByRole } = render(
6679
<Modal id={id} show>

0 commit comments

Comments
 (0)