diff --git a/packages/react/src/components/Coachmark/Coachmark.base.tsx b/packages/react/src/components/Coachmark/Coachmark.base.tsx index 2da4bbd14e69c..6ffe5df171362 100644 --- a/packages/react/src/components/Coachmark/Coachmark.base.tsx +++ b/packages/react/src/components/Coachmark/Coachmark.base.tsx @@ -23,6 +23,7 @@ import { FocusTrapZone } from '../../FocusTrapZone'; import { useAsync, useOnEvent, useSetTimeout, useWarnings } from '@fluentui/react-hooks'; import type { IRectangle } from '../../Utilities'; import type { IPositionedData } from '../../Positioning'; +import type { IPositioningContainerProps } from './PositioningContainer/PositioningContainer.types'; import type { ICoachmarkProps, ICoachmarkStyles, ICoachmarkStyleProps } from './Coachmark.types'; import type { IBeakProps } from './Beak/Beak.types'; @@ -401,6 +402,15 @@ function useDeprecationWarning(props: ICoachmarkProps) { } } +function useGetBounds(props: ICoachmarkProps): IRectangle | undefined { + const async = useAsync(); + const [bounds, setBounds] = React.useState(); + React.useEffect(() => { + async.requestAnimationFrame(() => setBounds(getBounds(props.isPositionForced, props.positioningContainerProps))); + }, [async, props.isPositionForced, props.positioningContainerProps]); + return bounds; +} + const COMPONENT_NAME = 'CoachmarkBase'; export const CoachmarkBase: React.FunctionComponent = React.forwardRef< @@ -431,7 +441,6 @@ export const CoachmarkBase: React.FunctionComponent = React.for target, color, positioningContainerProps, - isPositionForced, ariaDescribedBy, ariaDescribedByText, ariaLabelledBy, @@ -468,17 +477,6 @@ export const CoachmarkBase: React.FunctionComponent = React.for const finalHeight: number | undefined = isCollapsed ? COACHMARK_HEIGHT : entityInnerHostRect.height; - function useGetBounds(): IRectangle | undefined { - const async = useAsync(); - const [bounds, setBounds] = React.useState(); - const updateAsyncPosition = (): void => { - async.requestAnimationFrame(() => setBounds(getBounds({ isPositionForced, positioningContainerProps }))); - }; - // eslint-disable-next-line react-hooks/exhaustive-deps - React.useEffect(updateAsyncPosition, [async, isPositionForced, positioningContainerProps]); - return bounds; - } - return ( = React.for finalHeight={finalHeight} ref={forwardedRef} onPositioned={onPositioned} - bounds={useGetBounds()} + bounds={useGetBounds(props)} {...positioningContainerProps} >
@@ -538,10 +536,10 @@ export const CoachmarkBase: React.FunctionComponent = React.for }); CoachmarkBase.displayName = COMPONENT_NAME; -function getBounds({ - isPositionForced, - positioningContainerProps, -}: Pick): IRectangle | undefined { +function getBounds( + isPositionForced?: boolean, + positioningContainerProps?: IPositioningContainerProps, +): IRectangle | undefined { if (isPositionForced) { // If directionalHint direction is the top or bottom auto edge, then we want to set the left/right bounds // to the window x-axis to have auto positioning work correctly.