tooltip icon indicating copy to clipboard operation
tooltip copied to clipboard

Auto-position arrow

Open satazor opened this issue 9 years ago • 7 comments

When overflow.adjustX and/or overflow.adjustY is true, then the box was auto-adjusted to not go offscreen. In those cases, I expected the arrow to be positioned accordingly.

In the screenshot below, the arrow position should be pointing to the deprecated flag.

screen shot 2016-09-19 at 14 19 04

satazor avatar Sep 19 '16 13:09 satazor

I've managed to solve this with onPopupAlign:

// ./util/placeArrow.js

import positions from 'positions';

const placementsMap = {
    tc: 'top center',
    bc: 'bottom center',
    cl: 'center right',
    cr: 'center left',
};

export default function placeArrow(tooltipEl, align) {
    const arrowEl = tooltipEl.querySelector('.tooltip-component-arrow');
    const targetEl = this.getRootDomNode();  // eslint-disable-line no-invalid-this

    const position = positions(arrowEl, placementsMap[align.points[0]], targetEl, placementsMap[align.points[1]]);

    if (align.points[0] === 'tc' || align.points[0] === 'bc') {
        arrowEl.style.top = '';
        arrowEl.style.left = `${position.left}px`;
    } else {
        arrowEl.style.top = `${position.top}px`;
        arrowEl.style.left = '';
    }
}

then just set the onPopupAlign to placeArrow. Also note that you need to install positions module.

Anyway I would love to have this built in.

satazor avatar Sep 19 '16 14:09 satazor

Can we have this built in? It looks awesome!

jpalala avatar Feb 22 '17 08:02 jpalala

If the above snippet doesn't work for you, try changing .tooltip-component-arrow to .rc-tooltip-arrow

royshouvik avatar Apr 09 '17 12:04 royshouvik

Looks like someone created a PR https://github.com/react-component/tooltip/pull/166

BenjaminEckardt avatar Feb 19 '19 09:02 BenjaminEckardt

@satazor can you give an example of how apply this solution, please? thanks in advance

vicchirino avatar Jul 19 '19 22:07 vicchirino

Hello @vicchirino, check this out: https://github.com/npms-io/npms-www/tree/master/src/shared/components/tooltip. The tooltip component is using utils/placeArrow and utils/checkEdges

satazor avatar Jul 20 '19 01:07 satazor

Is there any update about this issue being getting resolved?

tusharag-19 avatar Dec 01 '22 03:12 tusharag-19