Skip to content

Commit

Permalink
Fixed tooltip alignment in mobile settings view (#7515)
Browse files Browse the repository at this point in the history
Made tooltip design aligned with Wordpress/tooltip and made it mobile-compatible
  • Loading branch information
naman03malhotra authored Oct 25, 2023
1 parent 6ba3d6d commit 76caedf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-6950-fix-imp-mobile-tooltip
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fixed tooltip alignment for mobile view in payment settings
15 changes: 0 additions & 15 deletions client/components/tooltip/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,6 @@
padding: 10px;
text-align: center;

&::after {
content: ' ';
position: absolute;

// assuming all the tooltips are displayed at the top of the wrapped element.
// no need to complicate things since that's the only use case at the moment.
bottom: 0;
left: 50%;
transform: translate( -50%, 22px );
border: solid 15px transparent;
border-top-color: $gray-900;
// Ensure the tooltip arrow does not obscure the mouse target element.
pointer-events: none;
}

a {
color: var( --wp-admin-theme-color, $gutenberg-blue );
}
Expand Down
11 changes: 10 additions & 1 deletion client/components/tooltip/tooltip-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,18 @@ const TooltipBase: React.FC< TooltipBaseProps > = ( {
wrappedElement.offsetWidth / 2 + wrappedElementRect.left;
const tooltipWidth = tooltipElement.offsetWidth;
let tooltipLeft = elementMiddle - tooltipWidth / 2;
const tooltipRight =
window.innerWidth -
( wrappedElementRect.left + tooltipElement.offsetWidth );

if ( tooltipLeft < 0 ) {
tooltipLeft = 10;
// create a gap with the left edge if the element is out of view port
tooltipLeft = 45;
} else if ( tooltipRight < 0 ) {
// create a gap with the right edge if the element is out of view port
tooltipLeft = tooltipLeft - 85;
}

tooltipElement.style.left = `${ tooltipLeft }px`;

// make it visible only after all the calculations are done.
Expand Down

0 comments on commit 76caedf

Please sign in to comment.