mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-14 20:40:17 -05:00
Merge pull request #21733 from overleaf/jel-tooltip-badges
[web] Fix tooltips not always added to badge links GitOrigin-RevId: d4e80f3bb62bce2083dec261ffd5634510310127
This commit is contained in:
parent
8b0b923063
commit
aa782b2737
1 changed files with 27 additions and 10 deletions
|
@ -1,12 +1,23 @@
|
||||||
import { Tooltip } from 'bootstrap-5'
|
import { Tooltip } from 'bootstrap-5'
|
||||||
|
|
||||||
|
function getElementWidth(el: Element) {
|
||||||
|
const elComputedStyle = window.getComputedStyle(el)
|
||||||
|
const elPaddingX =
|
||||||
|
parseFloat(elComputedStyle.paddingLeft) +
|
||||||
|
parseFloat(elComputedStyle.paddingRight)
|
||||||
|
const elBorderX =
|
||||||
|
parseFloat(elComputedStyle.borderLeftWidth) +
|
||||||
|
parseFloat(elComputedStyle.borderRightWidth)
|
||||||
|
return el.scrollWidth - elPaddingX - elBorderX
|
||||||
|
}
|
||||||
|
|
||||||
const footerLanguageElement = document.querySelector(
|
const footerLanguageElement = document.querySelector(
|
||||||
'[data-ol-lang-selector-tooltip]'
|
'[data-ol-lang-selector-tooltip]'
|
||||||
) as Element
|
) as Element
|
||||||
|
|
||||||
const allTooltips = document.querySelectorAll('[data-bs-toggle="tooltip"]')
|
const allTooltips = document.querySelectorAll('[data-bs-toggle="tooltip"]')
|
||||||
|
|
||||||
const possibleTooltips = document.querySelectorAll(
|
const possibleBadgeTooltips = document.querySelectorAll(
|
||||||
'[data-bs-toggle="tooltip-if-needed"]'
|
'[data-bs-toggle="tooltip-if-needed"]'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,14 +29,20 @@ allTooltips.forEach(element => {
|
||||||
const tooltip = new Tooltip(element)
|
const tooltip = new Tooltip(element)
|
||||||
})
|
})
|
||||||
|
|
||||||
possibleTooltips.forEach(element => {
|
possibleBadgeTooltips.forEach(element => {
|
||||||
// put data-bs-toggle="tooltip-if-needed" on .badge-content
|
// Put data-bs-toggle="tooltip-if-needed" on .badge-content
|
||||||
// then tooltip is only shown if .badge is clipped due to max-width
|
// then tooltip is only shown if content is clipped due to max-width on .badge
|
||||||
if (
|
// Due to font loading, the width calculated on page load might change, so we might
|
||||||
element.parentElement &&
|
// incorrectly determine a tooltip is not needed. This is why max-width will always be set to none
|
||||||
element.scrollWidth > element.parentElement?.scrollWidth
|
// if no tooltip is shown so that content is fully visible in those scenarios.
|
||||||
) {
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
if (element.parentElement) {
|
||||||
const tooltip = new Tooltip(element)
|
const parentWidth = getElementWidth(element.parentElement)
|
||||||
|
if (element.scrollWidth > parentWidth) {
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
const tooltip = new Tooltip(element)
|
||||||
|
} else {
|
||||||
|
element.parentElement.style.maxWidth = 'none'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue