Skip to content

Commit 3af8a94

Browse files
TuxedoFishtay1orjoneskodiakhq[bot]
authored
fix(tooltip): Fix tooltip alignment aligned on right hand side of container (#9606)
* fix(tooltip): add auto-update on set state * fix(tooltip): safely check the size is different Co-authored-by: Taylor Jones <tay1orjones@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 75646c0 commit 3af8a94

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

packages/react/src/internal/FloatingMenu.js

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class FloatingMenu extends React.Component {
261261
*
262262
* @private
263263
*/
264-
_updateMenuSize = (prevProps = {}) => {
264+
_updateMenuSize = (prevProps = {}, isAdjustment = false) => {
265265
const menuBody = this._menuBody;
266266
warning(
267267
menuBody,
@@ -279,7 +279,8 @@ class FloatingMenu extends React.Component {
279279

280280
if (
281281
hasChangeInOffset(oldMenuOffset, menuOffset) ||
282-
oldMenuDirection !== menuDirection
282+
oldMenuDirection !== menuDirection ||
283+
isAdjustment
283284
) {
284285
const { flipped, triggerRef } = this.props;
285286
const { current: triggerEl } = triggerRef;
@@ -293,20 +294,30 @@ class FloatingMenu extends React.Component {
293294
// a) Menu body has `display:none`
294295
// b) `menuOffset` as a callback returns `undefined` (The callback saw that it couldn't calculate the value)
295296
if ((menuSize.width > 0 && menuSize.height > 0) || !offset) {
296-
this.setState({
297-
floatingPosition: getFloatingPosition({
298-
menuSize,
299-
refPosition,
300-
direction: menuDirection,
301-
offset,
302-
scrollX: window.pageXOffset,
303-
scrollY: window.pageYOffset,
304-
container: {
305-
rect: this.props.target().getBoundingClientRect(),
306-
position: getComputedStyle(this.props.target()).position,
307-
},
308-
}),
309-
});
297+
this.setState(
298+
{
299+
floatingPosition: getFloatingPosition({
300+
menuSize,
301+
refPosition,
302+
direction: menuDirection,
303+
offset,
304+
scrollX: window.pageXOffset,
305+
scrollY: window.pageYOffset,
306+
container: {
307+
rect: this.props.target().getBoundingClientRect(),
308+
position: getComputedStyle(this.props.target()).position,
309+
},
310+
}),
311+
},
312+
() => {
313+
if (!isAdjustment) {
314+
const newMenuSize = menuBody.getBoundingClientRect();
315+
if (newMenuSize !== menuSize) {
316+
this._updateMenuSize(this.props, true);
317+
}
318+
}
319+
}
320+
);
310321
}
311322
}
312323
};

0 commit comments

Comments
 (0)