Popper position update (#212)

This commit is contained in:
Ilya Y 2023-09-07 21:45:22 +03:00 committed by GitHub
parent 5f40bb8465
commit 5d116ede22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -134,7 +134,9 @@ export const FullArticle = (props: Props) => {
const tooltipElements: NodeListOf<HTMLElement> = document.querySelectorAll(
'[data-toggle="tooltip"], footnote'
)
if (!tooltipElements) return
if (!tooltipElements) {
return
}
tooltipElements.forEach((element) => {
const tooltip = document.createElement('div')
tooltip.classList.add(styles.tooltip)
@ -149,7 +151,8 @@ export const FullArticle = (props: Props) => {
if (element.hasAttribute('href')) {
element.setAttribute('href', 'javascript: void(0);')
}
createPopper(element, tooltip, {
const popperInstance = createPopper(element, tooltip, {
placement: 'top',
modifiers: [
{
@ -161,13 +164,16 @@ export const FullArticle = (props: Props) => {
options: {
offset: [0, 8]
}
},
{
name: 'flip',
options: { fallbackPlacements: ['top'] }
}
]
})
tooltip.style.visibility = 'hidden'
let isTooltipVisible = false
const handleClick = () => {
if (isTooltipVisible) {
tooltip.style.visibility = 'hidden'
@ -176,6 +182,8 @@ export const FullArticle = (props: Props) => {
tooltip.style.visibility = 'visible'
isTooltipVisible = true
}
popperInstance.update()
}
const handleDocumentClick = (e) => {