@@ -7,7 +7,7 @@ import type {FocusZoneHookSettings} from '../hooks/useFocusZone'
77import { useFocusZone } from '../hooks/useFocusZone'
88import { useAnchoredPosition , useProvidedRefOrCreate , useRenderForcingRef } from '../hooks'
99import { useId } from '../hooks/useId'
10- import type { PositionSettings } from '@primer/behaviors'
10+ import type { AnchorPosition , PositionSettings } from '@primer/behaviors'
1111import { useResponsiveValue , type ResponsiveValue } from '../hooks/useResponsiveValue'
1212
1313interface AnchoredOverlayPropsWithAnchor {
@@ -98,6 +98,10 @@ interface AnchoredOverlayBaseProps extends Pick<OverlayProps, 'height' | 'width'
9898 * Optional prop to set variant for narrow screen sizes
9999 */
100100 variant ?: ResponsiveValue < 'anchored' , 'anchored' | 'fullscreen' >
101+ /**
102+ * An override to the internal position that will be used to position the overlay.
103+ */
104+ onPositionChange ?: ( { position} : { position : AnchorPosition } ) => void
101105}
102106
103107export type AnchoredOverlayProps = AnchoredOverlayBaseProps &
@@ -129,6 +133,7 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr
129133 pinPosition,
130134 variant = { regular : 'anchored' , narrow : 'anchored' } ,
131135 preventOverflow = true ,
136+ onPositionChange,
132137} ) => {
133138 const anchorRef = useProvidedRefOrCreate ( externalAnchorRef )
134139 const [ overlayRef , updateOverlayRef ] = useRenderForcingRef < HTMLDivElement > ( )
@@ -162,6 +167,12 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr
162167 [ open , onOpen , onClose ] ,
163168 )
164169
170+ const positionChange = ( position : AnchorPosition | undefined ) => {
171+ if ( onPositionChange && position ) {
172+ onPositionChange ( { position} )
173+ }
174+ }
175+
165176 const { position} = useAnchoredPosition (
166177 {
167178 anchorElementRef : anchorRef ,
@@ -171,6 +182,7 @@ export const AnchoredOverlay: React.FC<React.PropsWithChildren<AnchoredOverlayPr
171182 align,
172183 alignmentOffset,
173184 anchorOffset,
185+ onPositionChange : positionChange ,
174186 } ,
175187 [ overlayRef . current ] ,
176188 )
0 commit comments