File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,28 @@ components with focus management.
115
115
Pass the ` menuTarget ` prop to render the ` Menu ` inside the modal or any specific
116
116
element where you want it to render:
117
117
118
+ ## Managing the ` menuTarget ` prop with React refs
119
+ Because React does not trigger re-renders when a ref's ` .current ` value changes,
120
+ you must capture the ref value in state to update the ` menuTarget ` prop.
121
+ ``` tsx
122
+ const Component = () => {
123
+ const containerRef = useRef <HTMLDivElement >(null );
124
+ const [target, setTarget] = useState <HTMLDivElement | undefined >(undefined );
125
+ useEffect (() => {
126
+ if (containerRef .current ) {
127
+ setTarget (containerRef .current );
128
+ }
129
+ }, []);
130
+ return (
131
+ <div ref = { containerRef } >
132
+ <MenuButton label = " Actions" menuTarget = { target } >
133
+ <MenuItem label = " First action" />
134
+ </MenuButton >
135
+ </div >
136
+ );
137
+ };
138
+ ```
139
+
118
140
## Experimental Auto Align
119
141
120
142
<Canvas
You can’t perform that action at this time.
0 commit comments