Skip to content

Commit 347e2f6

Browse files
fix(Coachmark): Remove positioning regression and update bounds on resize (#27782)
* fix: Update bounds on resize. * change file * remove comment * fixing vr-tests * updating stories * restoring files * restoring previous files --------- Co-authored-by: Micah Godbolt <mgodbolt@microsoft.com>
1 parent 3aecae7 commit 347e2f6

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix(Coachmark): Fix positioning regression and update bounds on resize.",
4+
"packageName": "@fluentui/react",
5+
"email": "esteban.230@hotmail.com",
6+
"dependentChangeType": "patch"
7+
}

packages/react/src/components/Coachmark/Coachmark.base.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ function useProximityHandlers(
247247
props: ICoachmarkProps,
248248
translateAnimationContainer: React.RefObject<HTMLDivElement>,
249249
openCoachmark: () => void,
250+
setBounds: (bounds: IRectangle | undefined) => void,
250251
) {
251252
const { setTimeout, clearTimeout } = useSetTimeout();
252253

@@ -285,6 +286,7 @@ function useProximityHandlers(
285286
timeoutIds.push(
286287
setTimeout((): void => {
287288
setTargetElementRect();
289+
setBounds(getBounds(props.isPositionForced, props.positioningContainerProps));
288290
}, 100),
289291
);
290292
});
@@ -402,15 +404,6 @@ function useDeprecationWarning(props: ICoachmarkProps) {
402404
}
403405
}
404406

405-
function useGetBounds(props: ICoachmarkProps): IRectangle | undefined {
406-
const async = useAsync();
407-
const [bounds, setBounds] = React.useState<IRectangle | undefined>();
408-
React.useEffect(() => {
409-
async.requestAnimationFrame(() => setBounds(getBounds(props.isPositionForced, props.positioningContainerProps)));
410-
}, [async, props.isPositionForced, props.positioningContainerProps]);
411-
return bounds;
412-
}
413-
414407
const COMPONENT_NAME = 'CoachmarkBase';
415408

416409
export const CoachmarkBase: React.FunctionComponent<ICoachmarkProps> = React.forwardRef<
@@ -426,14 +419,21 @@ export const CoachmarkBase: React.FunctionComponent<ICoachmarkProps> = React.for
426419
const [isCollapsed, openCoachmark] = useCollapsedState(props, entityInnerHostElementRef);
427420
const [beakPositioningProps, transformOrigin] = useBeakPosition(props, targetAlignment, targetPosition);
428421
const [isMeasuring, entityInnerHostRect] = useEntityHostMeasurements(props, entityInnerHostElementRef);
422+
const [bounds, setBounds] = React.useState<IRectangle | undefined>(
423+
getBounds(props.isPositionForced, props.positioningContainerProps),
424+
);
429425
const alertText = useAriaAlert(props);
430426
const entityHost = useAutoFocus(props);
431427

432428
useListeners(props, translateAnimationContainer, openCoachmark);
433429
useComponentRef(props);
434-
useProximityHandlers(props, translateAnimationContainer, openCoachmark);
430+
useProximityHandlers(props, translateAnimationContainer, openCoachmark, setBounds);
435431
useDeprecationWarning(props);
436432

433+
React.useEffect(() => {
434+
setBounds(getBounds(props.isPositionForced, props.positioningContainerProps));
435+
}, [props.isPositionForced, props.positioningContainerProps]);
436+
437437
const {
438438
beaconColorOne,
439439
beaconColorTwo,
@@ -484,7 +484,7 @@ export const CoachmarkBase: React.FunctionComponent<ICoachmarkProps> = React.for
484484
finalHeight={finalHeight}
485485
ref={forwardedRef}
486486
onPositioned={onPositioned}
487-
bounds={useGetBounds(props)}
487+
bounds={bounds}
488488
{...positioningContainerProps}
489489
>
490490
<div className={classNames.root}>

0 commit comments

Comments
 (0)