From 796c5e8b6b9e2ba2b97c6144f64a756e76a947a9 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 4 Oct 2020 12:04:09 -0700 Subject: [PATCH] Fixed: Episode history details tooltip jumping around Closes #3965 --- frontend/src/Components/Tooltip/Tooltip.css | 32 +++++++++++++++++ frontend/src/Components/Tooltip/Tooltip.js | 40 ++++++++++++++++++--- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/frontend/src/Components/Tooltip/Tooltip.css b/frontend/src/Components/Tooltip/Tooltip.css index b07dafefa..c5ddc7272 100644 --- a/frontend/src/Components/Tooltip/Tooltip.css +++ b/frontend/src/Components/Tooltip/Tooltip.css @@ -156,3 +156,35 @@ .body { padding: 5px; } + +.verticalContainer { + max-height: 300px; +} + +.horizontalContainer { + max-width: calc($breakpointExtraSmall - 20px); +} + +@media only screen and (min-width: $breakpointExtraSmall) { + .horizontalContainer { + max-width: calc($breakpointSmall * 0.8); + } +} + +@media only screen and (min-width: $breakpointSmall) { + .horizontalContainer { + max-width: calc($breakpointMedium * 0.8); + } +} + +@media only screen and (min-width: $breakpointMedium) { + .horizontalContainer { + max-width: calc($breakpointLarge * 0.8); + } +} + +/* @media only screen and (max-width: $breakpointLarge) { + .horizontalContainer { + max-width: calc($breakpointLarge * 0.8); + } +} */ diff --git a/frontend/src/Components/Tooltip/Tooltip.js b/frontend/src/Components/Tooltip/Tooltip.js index 53d0550ed..d10e95a50 100644 --- a/frontend/src/Components/Tooltip/Tooltip.js +++ b/frontend/src/Components/Tooltip/Tooltip.js @@ -5,8 +5,29 @@ import classNames from 'classnames'; import { isMobile as isMobileUtil } from 'Utilities/mobile'; import { kinds, tooltipPositions } from 'Helpers/Props'; import Portal from 'Components/Portal'; +import dimensions from 'Styles/Variables/dimensions'; import styles from './Tooltip.css'; +let maxWidth = null; + +function getMaxWidth() { + const windowWidth = window.innerWidth; + + if (windowWidth > parseInt(dimensions.breakpointLarge)) { + maxWidth = 800; + } + + if (windowWidth > parseInt(dimensions.breakpointMedium)) { + maxWidth = 650; + } + + if (windowWidth > parseInt(dimensions.breakpointSmall)) { + maxWidth = 500; + } + + maxWidth = 450; +} + class Tooltip extends Component { // @@ -17,6 +38,7 @@ class Tooltip extends Component { this._scheduleUpdate = null; this._closeTimeout = null; + this._maxWidth = maxWidth || getMaxWidth(); this.state = { isOpen: false @@ -54,9 +76,11 @@ class Tooltip extends Component { } else if ((/^bottom/).test(data.placement)) { data.styles.maxHeight = windowHeight - bottom - 20; } else if ((/^right/).test(data.placement)) { - data.styles.maxWidth = windowWidth - right - 50; + data.styles.maxWidth = Math.min(this._maxWidth, windowWidth - right - 20); + data.styles.maxHeight = top - 20; } else { - data.styles.maxWidth = left - 35; + data.styles.maxWidth = Math.min(this._maxWidth, left - 20); + data.styles.maxHeight = top - 20; } return data; @@ -144,10 +168,16 @@ class Tooltip extends Component { {({ ref, style, placement, arrowProps, scheduleUpdate }) => { this._scheduleUpdate = scheduleUpdate; + const popperPlacement = placement ? placement.split('-')[0] : position; + const vertical = popperPlacement === 'top' || popperPlacement === 'bottom'; + return (