Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Tooltip: fix arrow persistence #2592

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 34 additions & 31 deletions packages/eds-core-react/src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
SVGProps,
cloneElement,
useMemo,
useEffect,
} from 'react'
import styled from 'styled-components'
import {
Expand Down Expand Up @@ -116,39 +117,41 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
useDismiss(context),
])

const staticSide = {
top: 'bottom',
right: 'left',
bottom: 'top',
left: 'right',
}[finalPlacement.split('-')[0]]
useEffect(() => {
const staticSide = {
top: 'bottom',
right: 'left',
bottom: 'top',
left: 'right',
}[finalPlacement.split('-')[0]]

let arrowTransform = 'none'
switch (staticSide) {
case 'right':
arrowTransform = 'rotateY(180deg)'
break
case 'left':
arrowTransform = 'none'
break
case 'top':
arrowTransform = 'rotate(90deg)'
break
case 'bottom':
arrowTransform = 'rotate(-90deg)'
break
}
let arrowTransform = 'none'
switch (staticSide) {
case 'right':
arrowTransform = 'rotateY(180deg)'
break
case 'left':
arrowTransform = 'none'
break
case 'top':
arrowTransform = 'rotate(90deg)'
break
case 'bottom':
arrowTransform = 'rotate(-90deg)'
break
}

if (arrowRef.current) {
Object.assign(arrowRef.current.style, {
left: arrowX != null ? `${arrowX}px` : '',
top: arrowY != null ? `${arrowY}px` : '',
right: '',
bottom: '',
[staticSide]: '-6px',
transform: arrowTransform,
})
}
if (arrowRef.current) {
Object.assign(arrowRef.current.style, {
left: arrowX != null ? `${arrowX}px` : '',
top: arrowY != null ? `${arrowY}px` : '',
right: '',
bottom: '',
[staticSide]: '-6px',
transform: arrowTransform,
})
}
})

const updatedChildren = cloneElement(children, {
...getReferenceProps({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ exports[`Tooltip Matches snapshot 1`] = `
Tooltip
<div
class="c1"
style="top: -6px; transform: rotate(90deg);"
>
<svg
class="c2 arrowSvg"
Expand Down