Skip to content

Commit

Permalink
fix(Callout): Update useMaxHeight to check if the provided maxHeight …
Browse files Browse the repository at this point in the history
…is larger than the bounds (#27558)
  • Loading branch information
sopranopillow committed Apr 14, 2023
1 parent 92dd947 commit 97a9295
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix(Callout): Update useMaxHeight to check if the provided maxHeight will make the callout get cut off.",
"packageName": "@fluentui/react",
"email": "esteban.230@hotmail.com",
"dependentChangeType": "patch"
}
20 changes: 13 additions & 7 deletions packages/react/src/components/Callout/CalloutContent.base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,19 @@ function useMaxHeight(

React.useEffect(() => {
const { top: topBounds, bottom: bottomBounds } = getBounds() ?? {};
let calculatedHeight: number | undefined;

if (!calloutMaxHeight && !hidden) {
if (typeof top === 'number' && bottomBounds) {
setMaxHeight(bottomBounds - top);
} else if (typeof bottom === 'number' && typeof topBounds === 'number' && bottomBounds) {
setMaxHeight(bottomBounds - topBounds - bottom);
}
if (typeof top === 'number' && bottomBounds) {
calculatedHeight = bottomBounds - top;
} else if (typeof bottom === 'number' && typeof topBounds === 'number' && bottomBounds) {
calculatedHeight = bottomBounds - topBounds - bottom;
}

if (
(!calloutMaxHeight && !hidden) ||
(calloutMaxHeight && calculatedHeight && calloutMaxHeight > calculatedHeight)
) {
setMaxHeight(calculatedHeight);
} else if (calloutMaxHeight) {
setMaxHeight(calloutMaxHeight);
} else {
Expand Down Expand Up @@ -476,7 +482,7 @@ export const CalloutContentBase: React.FunctionComponent<ICalloutProps> = React.
const classNames = getClassNames(styles!, {
theme: props.theme!,
className,
overflowYHidden: overflowYHidden,
overflowYHidden,
calloutWidth,
positions,
beakWidth,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const getStyles = (props: ICalloutContentStyleProps): ICalloutContentStyl
},
getBeakStyle(beakWidth),
backgroundColor && {
backgroundColor: backgroundColor,
backgroundColor,
},
],
beakCurtain: [
Expand Down Expand Up @@ -106,7 +106,7 @@ export const getStyles = (props: ICalloutContentStyleProps): ICalloutContentStyl
overflowY: 'hidden',
},
backgroundColor && {
backgroundColor: backgroundColor,
backgroundColor,
},
],
};
Expand Down

0 comments on commit 97a9295

Please sign in to comment.