reactjs-popup icon indicating copy to clipboard operation
reactjs-popup copied to clipboard

Position is not recalculated on content change

Open Ploppz opened this issue 5 years ago • 4 comments

https://codesandbox.io/s/reactjs-popup-issue-template-8hzrh

As you can see, the position of the popup is wrong when the contents is updated. In my application, I only start loading the contents of the popup once the user clicks the trigger of the popup, so the popup will be empty (or perhaps some "loading..." text) for a while just as in the above demo.

Ploppz avatar Nov 29 '19 13:11 Ploppz

+1

Experiencing the same issue.

svobom57 avatar Feb 24 '20 17:02 svobom57

I ended up fixing this by adding a reposition action on the imperativeHandle

  useImperativeHandle(ref, function () {
    return {
      open: function open() {
        openPopup();
      },
      close: function close() {
        closePopup();
      },
      toggle: function toggle() {
        togglePopup();
      },
      reposition: function reposition() {
        setPosition();
      }
    };
  }); // set Position

And in my code:

return <Popup
            ref={popupRef}
            trigger={...}
        >
            <Menu contentChanged={() => popupRef.current?.reposition()} />
        </Popup>

And in the Menu

const [content, setContent] = useState()
useEffect(contentChanged, [content)

It aint the cleanest way of doing it, but so far it seems to work well

yasserf avatar Jun 26 '21 11:06 yasserf

I am having the same problem as described.

What's the status of this issue?

rvision avatar Feb 03 '22 09:02 rvision

What I came up with is to add a prop repositionOnResize and trigger an event whenever the content of the popup changed with window.dispatchEvent(new Event('resize'));

Zhdanown avatar Feb 07 '22 23:02 Zhdanown