Skip to content

Commit

Permalink
fix: fix #tooltip mouse position usage when width is larger than 400px
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Mar 24, 2021
1 parent cb17fb2 commit bfb8058
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/dnb-eufemia/src/components/tooltip/TooltipContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import React from 'react'
import PropTypes from 'prop-types'
import { isTrue } from '../../shared/component-helper'
import { getOffsetLeft } from '../../shared/helpers'
import classnames from 'classnames'

export default class TooltipContainer extends React.PureComponent {
Expand Down Expand Up @@ -158,10 +159,16 @@ export default class TooltipContainer extends React.PureComponent {
const top = scrollY + rect.top

// Use Mouse position when target is too wide
const useMouseWhen = targetSize.width > 400
const mousePos =
this.props.clientX -
getOffsetLeft(target) +
rect.left / 2 +
(this._rootRef.current ? this._rootRef.current.offsetWidth : 0)
const widthBased = scrollX + rect.left
const left =
parseFloat(targetSize.width) > 400 && this.props.clientX
? this.props.clientX - rect.left
: scrollX + rect.left
useMouseWhen && mousePos < targetSize.width ? mousePos : widthBased

const style = {}

if (align === 'left') {
Expand Down

0 comments on commit bfb8058

Please sign in to comment.