Skip to content

Commit c057c1d

Browse files
committed
dialog: fix unattached ref bug (#336)
1 parent 64e348a commit c057c1d

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import "@reach/dialog/styles.css";
2+
3+
import React from "react";
4+
import { DialogOverlay, DialogContent } from "@reach/dialog";
5+
6+
export let name = "With Wrapped Components";
7+
8+
const FilteredDialogContent = React.forwardRef(({ fakeProp, ...rest }, ref) => (
9+
<DialogContent
10+
{...rest}
11+
ref={ref}
12+
style={{ boxShadow: "0px 10px 50px hsla(0, 0%, 0%, 0.33)" }}
13+
/>
14+
));
15+
16+
const FilteredDialogOverlay = React.forwardRef(({ fakeProp, ...rest }, ref) => (
17+
<DialogOverlay
18+
{...rest}
19+
ref={ref}
20+
style={{ background: "rgba(0, 50, 150, 0.9)" }}
21+
/>
22+
));
23+
24+
export let Example = () => {
25+
const overlayRef = React.useRef(null);
26+
const contentRef = React.useRef(null);
27+
const [showDialog, setShowDialog] = React.useState(false);
28+
const open = () => setShowDialog(true);
29+
const close = () => setShowDialog(false);
30+
31+
return (
32+
<div>
33+
<button onClick={open}>Show Dialog</button>
34+
35+
<FilteredDialogOverlay
36+
fakeProp="this should do nothing"
37+
ref={overlayRef}
38+
isOpen={showDialog}
39+
onDismiss={close}
40+
>
41+
<FilteredDialogContent
42+
fakeProp="blah"
43+
aria-label="Announcement"
44+
ref={contentRef}
45+
>
46+
<p>Got a case of the blues?</p>
47+
<button onClick={close}>So blue</button>
48+
</FilteredDialogContent>
49+
</FilteredDialogOverlay>
50+
</div>
51+
);
52+
};

packages/dialog/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const DialogInner = React.forwardRef(function DialogInner(
4949
const overlayNode = React.useRef(null);
5050
const ref = useForkedRef(overlayNode, forwardedRef);
5151

52-
React.useEffect(() => createAriaHider(forwardedRef.current), [forwardedRef]);
52+
React.useEffect(() => createAriaHider(overlayNode.current), []);
5353

5454
return (
5555
<FocusLock

0 commit comments

Comments
 (0)