react-tooltip icon indicating copy to clipboard operation
react-tooltip copied to clipboard

Control position of tooltip's tip

Open kopijunkie opened this issue 9 years ago • 10 comments

Is there a way to control the tooltip's tip (the little arrow below the content bubble) more specifically? Example, say I want a tooltip's tip to be at the bottom left side of the tooltip as opposed to being always in the center depending on whether it is set to be top/bottom/left/right.

kopijunkie avatar Dec 01 '15 18:12 kopijunkie

no, have't supported this feature at the moment

wwayne avatar Dec 02 '15 01:12 wwayne

Yeah, a way to define the position of the tip would be great. We can do it now with some hacky global CSS, but it's not pretty.

techwraith avatar Aug 30 '16 21:08 techwraith

@Techwraith Could you share your hacky global CSS?

ms007 avatar Aug 30 '17 07:08 ms007

@Techwraith I'd also be interested in your hacky css

matthewfbenjamin avatar Jan 24 '18 22:01 matthewfbenjamin

I set 'left' property of '__react_component_tooltip.place-bottom' class and it helped in my case. Also I used 'data-offset' property.

.__react_component_tooltip.place-bottom:after { left: 90%; }

RuslanShohanov avatar Dec 04 '18 06:12 RuslanShohanov

+1

lopesc avatar Sep 19 '19 13:09 lopesc

+1

hunterraffety avatar Jul 07 '20 01:07 hunterraffety

After much playing around came up with this function to dynamically position the tip to account for the edges of the page:

export default ({ left, top }, event, triggerElement, tooltipElement) => {
  // left position of the element you hovered over + half it's width
  const arrowLeft = triggerElement.getBoundingClientRect().left + triggerElement.offsetWidth / 2;
  // the triggering element's bottom edge
  const arrowTop = triggerElement.getBoundingClientRect().top + triggerElement.offsetHeight + 4;
  const sheet = document.createElement('style');

  // after and before are black border triangle and white triangle
  sheet.innerHTML = `
    .__react_component_tooltip.place-bottom::after {
      position: fixed;
      top: ${arrowTop}px;
      left: ${arrowLeft}px;
    }
    .__react_component_tooltip.place-bottom::before {
      position: fixed;
      top: ${arrowTop - 1}px;
      left: ${arrowLeft}px;
    }
  `;
  document.body.appendChild(sheet);

  // https://github.com/wwayne/react-tooltip/issues/476
  return {
    top,
    left: Math.min(left, window.innerWidth - tooltipElement.offsetWidth),
  };
};

Usage:

import overridePosition from './overridePosition';

 <ReactTooltip
     overridePosition={overridePosition}
>
Screenshot 2020-07-09 16 14 09

tolicodes avatar Jul 09 '20 23:07 tolicodes

this works for me :)

.tooltip { &::after { left: 82% !important; } }

brenndap avatar Sep 03 '20 14:09 brenndap

This would be an awesome feature to be able to change the tip's position making it still be responsive.

ncesar avatar Jan 19 '22 15:01 ncesar

Hi guys, this will be handled on V5, thanks!

https://github.com/ReactTooltip/react-tooltip/discussions/812

danielbarion avatar Nov 09 '22 14:11 danielbarion

Hi guys, I'm sorry but for the initial v5, this option will not be available.

I can take a look and implement this in the future but at the moment, it's not possible by the amount of available time that I have.

danielbarion avatar Dec 05 '22 13:12 danielbarion