Skip to content

Commit

Permalink
fix(tooltip): Fix tooltip alignment aligned on right hand side of con…
Browse files Browse the repository at this point in the history
…tainer (#9606)

* fix(tooltip): add auto-update on set state

* fix(tooltip): safely check the size is different

Co-authored-by: Taylor Jones <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 6, 2021
1 parent 75646c0 commit 3af8a94
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions packages/react/src/internal/FloatingMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ class FloatingMenu extends React.Component {
*
* @private
*/
_updateMenuSize = (prevProps = {}) => {
_updateMenuSize = (prevProps = {}, isAdjustment = false) => {
const menuBody = this._menuBody;
warning(
menuBody,
Expand All @@ -279,7 +279,8 @@ class FloatingMenu extends React.Component {

if (
hasChangeInOffset(oldMenuOffset, menuOffset) ||
oldMenuDirection !== menuDirection
oldMenuDirection !== menuDirection ||
isAdjustment
) {
const { flipped, triggerRef } = this.props;
const { current: triggerEl } = triggerRef;
Expand All @@ -293,20 +294,30 @@ class FloatingMenu extends React.Component {
// a) Menu body has `display:none`
// b) `menuOffset` as a callback returns `undefined` (The callback saw that it couldn't calculate the value)
if ((menuSize.width > 0 && menuSize.height > 0) || !offset) {
this.setState({
floatingPosition: getFloatingPosition({
menuSize,
refPosition,
direction: menuDirection,
offset,
scrollX: window.pageXOffset,
scrollY: window.pageYOffset,
container: {
rect: this.props.target().getBoundingClientRect(),
position: getComputedStyle(this.props.target()).position,
},
}),
});
this.setState(
{
floatingPosition: getFloatingPosition({
menuSize,
refPosition,
direction: menuDirection,
offset,
scrollX: window.pageXOffset,
scrollY: window.pageYOffset,
container: {
rect: this.props.target().getBoundingClientRect(),
position: getComputedStyle(this.props.target()).position,
},
}),
},
() => {
if (!isAdjustment) {
const newMenuSize = menuBody.getBoundingClientRect();
if (newMenuSize !== menuSize) {
this._updateMenuSize(this.props, true);
}
}
}
);
}
}
};
Expand Down

0 comments on commit 3af8a94

Please sign in to comment.