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

Auto-position arrow #54

Open
satazor opened this issue Sep 19, 2016 · 7 comments
Open

Auto-position arrow #54

satazor opened this issue Sep 19, 2016 · 7 comments
Assignees

Comments

@satazor
Copy link

satazor commented Sep 19, 2016

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
Copy link
Author

satazor commented Sep 19, 2016

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.

@jpalala
Copy link

jpalala commented Feb 22, 2017

Can we have this built in? It looks awesome!

@royshouvik
Copy link

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

@BenjaminEckardt
Copy link

BenjaminEckardt commented Feb 19, 2019

Looks like someone created a PR #166

@vicchirino
Copy link

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

@satazor
Copy link
Author

satazor commented Jul 20, 2019

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

@tusharag-19
Copy link

Is there any update about this issue being getting resolved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants