@@ -28,6 +28,13 @@ export type PopoverProps = {
2828 children : React . ReactNode ;
2929 targetRef : React . RefObject < HTMLElement > ;
3030 position ?: Position ;
31+ /**
32+ * Render the popover markup, but hide it – used by MenuButton so that it
33+ * can have an `aria-controls` attribute even when its menu isn't open, and
34+ * used inside `Popover` as a hint that we can tell `useRect` to stop
35+ * observing for performance's sake.
36+ */
37+ hidden ?: boolean ;
3138 /**
3239 * Testing this API so we might accept additional nodes that apps can use to
3340 * determine the position of the popover. One example where it may be useful
@@ -58,13 +65,14 @@ const PopoverImpl = forwardRef<HTMLDivElement, PopoverProps>(
5865 targetRef,
5966 position = positionDefault ,
6067 unstable_observableRefs = [ ] ,
68+ hidden,
6169 ...props
6270 } ,
6371 forwardedRef
6472 ) {
6573 const popoverRef = useRef < HTMLDivElement > ( null ) ;
66- const popoverRect = useRect ( popoverRef ) ;
67- const targetRect = useRect ( targetRef ) ;
74+ const popoverRect = useRect ( popoverRef , ! hidden ) ;
75+ const targetRect = useRect ( targetRef , ! hidden ) ;
6876 const ref = useForkedRef ( popoverRef , forwardedRef ) ;
6977
7078 useSimulateTabNavigationForReactTree ( targetRef , popoverRef ) ;
@@ -73,6 +81,7 @@ const PopoverImpl = forwardRef<HTMLDivElement, PopoverProps>(
7381 < div
7482 data-reach-popover = ""
7583 ref = { ref }
84+ hidden = { hidden }
7685 { ...props }
7786 style = { {
7887 position : "absolute" ,
0 commit comments