question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React bootstrap OverlayTrigger Popover changes its placement when opening and closing

See original GitHub issue

Prerequisites

Describe the bug

I have a Popover that is wrapped in forwardRef and when i open/close it, its placement changes. Also on mobile resolution the Popover appears outside the parent element.

Expected behavior

I need the Popover to always be in the parent element and not outside of it.

To Reproduce

  1. Open sandbox (if you get root stylesheet error, refresh sandbox)
  2. Click on details button on any character
  3. Try open any popover

Reproducible Example

Sandbox - link

Screenshots

popover

What operating system(s) are you seeing the problem on?

Windows

What browser(s) are you seeing the problem on?

Chrome

What version of React-Bootstrap are you using?

2.3.0

What version of Bootstrap are you using?

5.1.3

Additional context

OverlayTrigger - src/components/DetailModal

               <div className="detail-modal__item__value episodes">
                {details.episode.map((ep: string) => {
                  return (
                    <OverlayTrigger
                      trigger="click"
                      placement="auto"
                      overlay={<EpisodePopover url={ep} />}
                      container={modalRef}
                      key={ep}
                    >
                      <p>{ep.split("episode/")[1]}</p>
                    </OverlayTrigger>
                  );
                })}
              </div>

Popover - src/components/Popovers/EpisodePopover

const EpisodePopover = React.forwardRef<HTMLDivElement, IPopoverProps>((props, ref) => {
    const { url } = props;
    const [episode, setEpisode] = React.useState<IEpisode>(null);
    const [isLoading, setLoading] = React.useState<boolean>(true);

    React.useEffect(() => {
      axios
        .get(url)
        .then(({ data }) => {
          setEpisode(data);
        })
        .catch((error) => {
          console.error("EpisodePopover", error);
        })
        .finally(() => {
          setLoading(false);
        });
    }, []); // eslint-disable-line

    return (
      <Popover className="popover" id="popover-basic" ref={ref} {...props}>
        <Popover.Body>
          {isLoading ? (
            <Loader />
          ) : (
            <>
              <div className="popover__item">
                <p className="popover__item__title">Name:</p>
                <p className="popover__item__value">{episode.name}</p>
              </div>
              <div className="popover__item">
                <p className="popover__item__title">Episode:</p>
                <p className="popover__item__value">{episode.episode}</p>
              </div>
              <div className="popover__item">
                <p className="popover__item__title">Air date:</p>
                <p className="popover__item__value">{episode.air_date}</p>
              </div>
            </>
          )}
        </Popover.Body>
      </Popover>
    );
  }
);

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
levanchiencommented, Aug 1, 2022

Demo with 2.5.0-beta.1 https://codesandbox.io/s/aged-wood-wkvkgx?file=/src/App.js

It’s positioned but with flicker Component from examples

@artygrand I fixed it by add position: absolute to Tooltip https://codesandbox.io/s/pedantic-sky-7ge7t1?file=/src/App.js

2reactions
artygrandcommented, Jul 26, 2022

Demo with 2.5.0-beta.1 https://codesandbox.io/s/aged-wood-wkvkgx?file=/src/App.js

It’s positioned but with flicker Component from examples

Read more comments on GitHub >

github_iconTop Results From Across the Web

Have React bootstrap component (popover) change position ...
This should do it: render() { return ( <OverlayTrigger ref="trigger" trigger="click" placement="top" overlay={this.
Read more >
Overlays | React-Bootstrap
A set of components for positioning beautiful overlays, tooltips, popovers, and anything else you need. Overview#. Things to know about the React-Bootstrap ......
Read more >
Change a React Bootstrap Component's Position Automatically
In this guide, you will learn how to create a popover component and update its position dynamically.
Read more >
[Solved]-Positioning react-bootstrap popover-Reactjs
its a bit hard to see what you are trying to do but you shouldn't be using the positionLeft and positionTop props, they...
Read more >
React-Bootstrap OverlayTrigger Component - GeeksforGeeks
It positions itself with the help of ref and style prop for our overlay component. We can use the following approach in ReactJS...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found