diff --git a/change/@fluentui-react-4050c913-450b-4833-a0a1-f59e28d3777b.json b/change/@fluentui-react-4050c913-450b-4833-a0a1-f59e28d3777b.json new file mode 100644 index 00000000000000..8c100df509fbf7 --- /dev/null +++ b/change/@fluentui-react-4050c913-450b-4833-a0a1-f59e28d3777b.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "fix: Coachmarks now properly animate when used in any of the center positions", + "packageName": "@fluentui/react", + "email": "mgodbolt@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/packages/react/src/components/Coachmark/PositioningContainer/PositioningContainer.tsx b/packages/react/src/components/Coachmark/PositioningContainer/PositioningContainer.tsx index 6a66378aaecd3c..47bd5ade5b353a 100644 --- a/packages/react/src/components/Coachmark/PositioningContainer/PositioningContainer.tsx +++ b/packages/react/src/components/Coachmark/PositioningContainer/PositioningContainer.tsx @@ -260,8 +260,10 @@ export function useHeightOffset( /** * Tracks the current height offset and updates during * the height animation when props.finalHeight is specified. + * State stored as object to ensure re-render even if the value does not change. + * See https://github.com/microsoft/fluentui/issues/23545 */ - const [heightOffset, setHeightOffset] = React.useState(0); + const [heightOffset, setHeightOffset] = React.useState<{ value: number }>({ value: 0 }); const async = useAsync(); const setHeightOffsetTimer = React.useRef(0); @@ -278,7 +280,7 @@ export function useHeightOffset( const cardCurrHeight: number = positioningContainerMainElem.offsetHeight; const scrollDiff: number = cardScrollHeight - cardCurrHeight; - setHeightOffset(heightOffset + scrollDiff); + setHeightOffset({ value: heightOffset.value + scrollDiff }); if (positioningContainerMainElem.offsetHeight < finalHeight) { setHeightOffsetEveryFrame(); @@ -292,7 +294,7 @@ export function useHeightOffset( // eslint-disable-next-line react-hooks/exhaustive-deps -- should only re-run if finalHeight changes React.useEffect(setHeightOffsetEveryFrame, [finalHeight]); - return heightOffset; + return heightOffset.value; } export const PositioningContainer: React.FunctionComponent = React.forwardRef<