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

Arrow position wrong for certain placements #403

Open
peterjcaulfield opened this issue Feb 9, 2021 · 3 comments
Open

Arrow position wrong for certain placements #403

peterjcaulfield opened this issue Feb 9, 2021 · 3 comments

Comments

@peterjcaulfield
Copy link

peterjcaulfield commented Feb 9, 2021

Reproduction demo

https://codesandbox.io/s/blue-leftpad-4of16?file=/src/Tooltip.tsx

I am using example code from the popper docs with styled components.

I want to make sure it is not related to styled components usage. Happy to create an additional example if this repro isn't good enough.

Steps to reproduce the problem

Please see code sandbox. Issue is present on load.

What is the expected behavior?

When I adjust the placement value the arrow should be positioned correctly via styles.arrow

What went wrong?

The arrow is positioned correctly for certain placements like top and bottom but is off for most other placements including variation placements like top-start, bottom-start etc.

Screenshot 2021-02-09 at 09 49 46

Any other comments?

I might be missing some userland code that I need to add here but my expectation was that the arrow would get positioned automagically via the translate styling being passed via styles.arrow.

Guidance on how to get the correct arrow position for all placement values would be greatly appreciated!

Packages versions

  • Popper.js: 2.6.0
  • react-popper: 2.2.4
@FezVrasta
Copy link
Member

I can't see anything in the codesandbox, code is missing.

From the screenshot it looks like you may want to add some margin to the arrow element so that it doesn't glitch like in your pictures.

@peterjcaulfield
Copy link
Author

peterjcaulfield commented Feb 9, 2021

@FezVrasta sorry about that VPN glitched when saving. It should be working now 👍

Thanks for the quick response.

I updated my usePopper invocation to set a padding on the arrow and things look good now.

const { styles, attributes } = usePopper(
    referenceElement.current,
    popperElement.current,
    {
      placement,
      modifiers: [
-       { name: "arrow", options: { element: arrowElement } },
+       { name: "arrow", options: { element: arrowElement, padding: 10 } },
        { name: "offset", options: { offset: [0, 8] } }
      ]
    }
  );

I have a couple of questions:

  • is it possible to configure this padding dynamically based on a placement via this API?
  • do you think it's worth updating the docs to include this padding in the example code so that all placements show up correctly?

@jayarjo
Copy link

jayarjo commented Jan 11, 2023

Adding arrow to react-popper is way more complicated than it should be.

@peterjcaulfield where in the docs is example that you mention linked? I only found it through the repo.

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

3 participants