Skip to content

Commit 72151b3

Browse files
authored
Fix tooltip positioning when containerPadding is set (#6577)
* Fix missing divider in Toast * Rough fix for tooltip positioning testing against chromatic, ideally calling updatePosition multiple times shouldnt break the positiong though... * alternative fix without relying on initial render * simplify fix for now
1 parent fabca84 commit 72151b3

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/@react-aria/overlays/src/useOverlayPosition.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ export function useOverlayPosition(props: AriaPositionProps): PositionAria {
171171
// This is so we don't have to delay autoFocus scrolling or delay applying preventScroll for popovers
172172
overlay.style.top = '';
173173
overlay.style.bottom = '';
174+
overlay.style.left = '';
175+
overlay.style.right = '';
176+
174177
Object.keys(position.position).forEach(key => overlay.style[key] = position.position[key] + 'px');
175178
overlay.style.maxHeight = position.maxHeight != null ? position.maxHeight + 'px' : undefined;
176179

packages/@react-spectrum/tooltip/chromatic/TooltipTrigger.stories.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ export const ContainerPadding50AtEdge: TooltipTriggerStory = {
7878
<Tooltip>Long tooltip message that just goes on and on again. But it just keeps going and going and going and going.</Tooltip>
7979
]
8080
},
81-
// padding is 231 so that it flips, this is because the tooltip has a width of 180px with the tip + 3px margin on the tooltip + 50px of container padding from this story
82-
// anything less than 232px padding on the div will result in a flip, so this is how we can visually test container padding
83-
// this uses slightly less than the required padding so that we account for any rounding and have a stable test
81+
82+
// Padding is 223 + 8px from the story margin itself = 231px of space from edge to button.
83+
// Size that the tooltip takes is 180 (tooltip width) + 3 (margin on overlay) + 50 (container padding) - 1 (offset applied via tooltiptrigger) = 232px
84+
// Note the above size that is calculated is slightly off, will need to update calculatePosition
8485
decorators: [(Story) => (
85-
<div style={{width: '100%', padding: '230px'}}>
86+
<div style={{width: '100%', padding: '223px'}}>
8687
<Story />
8788
</div>
8889
)]

0 commit comments

Comments
 (0)