1
1
import React , { useCallback , useEffect , useMemo , useRef , useState } from 'react'
2
- import Overlay from '../Overlay'
2
+ import Overlay , { OverlayProps } from '../Overlay'
3
3
import { useFocusTrap } from '../hooks/useFocusTrap'
4
4
import { useFocusZone } from '../hooks/useFocusZone'
5
5
import { useAnchoredPosition , useRenderForcingRef } from '../hooks'
@@ -9,7 +9,7 @@ function stopPropagation(event: React.UIEvent) {
9
9
event . stopPropagation ( )
10
10
}
11
11
12
- export interface AnchoredOverlayProps {
12
+ export interface AnchoredOverlayProps extends Pick < OverlayProps , 'height' | 'width' > {
13
13
/**
14
14
* A custom function component used to render the anchor element.
15
15
* Will receive the selected text as `children` prop when an item is activated.
@@ -36,7 +36,15 @@ export interface AnchoredOverlayProps {
36
36
* An `AnchoredOverlay` provides an anchor that will open a floating overlay positioned relative to the anchor.
37
37
* The overlay can be opened and navigated using keyboard or mouse.
38
38
*/
39
- export const AnchoredOverlay : React . FC < AnchoredOverlayProps > = ( { renderAnchor, children, open, onOpen, onClose} ) => {
39
+ export const AnchoredOverlay : React . FC < AnchoredOverlayProps > = ( {
40
+ renderAnchor,
41
+ children,
42
+ open,
43
+ onOpen,
44
+ onClose,
45
+ height,
46
+ width
47
+ } ) => {
40
48
const anchorRef = useRef < HTMLElement > ( null )
41
49
const [ overlayRef , updateOverlayRef ] = useRenderForcingRef < HTMLDivElement > ( )
42
50
const [ focusType , setFocusType ] = useState < null | 'anchor' | 'list' > ( open ? 'list' : null )
@@ -98,7 +106,7 @@ export const AnchoredOverlay: React.FC<AnchoredOverlayProps> = ({renderAnchor, c
98
106
return position && { top : `${ position . top } px` , left : `${ position . left } px` }
99
107
} , [ position ] )
100
108
101
- useFocusZone ( { containerRef : overlayRef , disabled : ! open || focusType !== 'list' || ! position } )
109
+ useFocusZone ( { containerRef : overlayRef , disabled : ! open || ! position } )
102
110
useFocusTrap ( { containerRef : overlayRef , disabled : ! open || focusType !== 'list' || ! position } )
103
111
104
112
return (
@@ -123,6 +131,8 @@ export const AnchoredOverlay: React.FC<AnchoredOverlayProps> = ({renderAnchor, c
123
131
visibility = { position ? 'visible' : 'hidden' }
124
132
onMouseDown = { stopPropagation }
125
133
onClick = { stopPropagation }
134
+ height = { height }
135
+ width = { width }
126
136
{ ...overlayPosition }
127
137
>
128
138
{ children }
0 commit comments