Skip to content
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix(Coachmark): Fix positioning regression and update bounds on resize.",
"packageName": "@fluentui/react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
22 changes: 11 additions & 11 deletions packages/react/src/components/Coachmark/Coachmark.base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ function useProximityHandlers(
props: ICoachmarkProps,
translateAnimationContainer: React.RefObject<HTMLDivElement>,
openCoachmark: () => void,
setBounds: (bounds: IRectangle | undefined) => void,
) {
const { setTimeout, clearTimeout } = useSetTimeout();

Expand Down Expand Up @@ -285,6 +286,7 @@ function useProximityHandlers(
timeoutIds.push(
setTimeout((): void => {
setTargetElementRect();
setBounds(getBounds(props.isPositionForced, props.positioningContainerProps));
}, 100),
);
});
Expand Down Expand Up @@ -402,15 +404,6 @@ function useDeprecationWarning(props: ICoachmarkProps) {
}
}

function useGetBounds(props: ICoachmarkProps): IRectangle | undefined {
const async = useAsync();
const [bounds, setBounds] = React.useState<IRectangle | undefined>();
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<ICoachmarkProps> = React.forwardRef<
Expand All @@ -426,14 +419,21 @@ export const CoachmarkBase: React.FunctionComponent<ICoachmarkProps> = React.for
const [isCollapsed, openCoachmark] = useCollapsedState(props, entityInnerHostElementRef);
const [beakPositioningProps, transformOrigin] = useBeakPosition(props, targetAlignment, targetPosition);
const [isMeasuring, entityInnerHostRect] = useEntityHostMeasurements(props, entityInnerHostElementRef);
const [bounds, setBounds] = React.useState<IRectangle | undefined>(
getBounds(props.isPositionForced, props.positioningContainerProps),
);
const alertText = useAriaAlert(props);
const entityHost = useAutoFocus(props);

useListeners(props, translateAnimationContainer, openCoachmark);
useComponentRef(props);
useProximityHandlers(props, translateAnimationContainer, openCoachmark);
useProximityHandlers(props, translateAnimationContainer, openCoachmark, setBounds);
useDeprecationWarning(props);

React.useEffect(() => {
setBounds(getBounds(props.isPositionForced, props.positioningContainerProps));
}, [props.isPositionForced, props.positioningContainerProps]);

const {
beaconColorOne,
beaconColorTwo,
Expand Down Expand Up @@ -484,7 +484,7 @@ export const CoachmarkBase: React.FunctionComponent<ICoachmarkProps> = React.for
finalHeight={finalHeight}
ref={forwardedRef}
onPositioned={onPositioned}
bounds={useGetBounds(props)}
bounds={bounds}
{...positioningContainerProps}
>
<div className={classNames.root}>
Expand Down