formaat-design / reshaped

Community repository for storing examples, reporting issues and tracking roadmap
https://reshaped.so
98 stars 3 forks source link

Popover.Content position is not updated when Popover.Trigger position changes #271

Open mareksed opened 1 week ago

mareksed commented 1 week ago

Describe the bug When position of Popover.Trigger is changed with transform: translate(), while popover content is open the position is not updated.

To Reproduce https://codesandbox.io/p/sandbox/reshaped-toolbar-zvqqmw?file=%2Fsrc%2FApp.js%3A10%2C31

Expected behavior Popover.Contents position is updated according to position change

Screenshots CleanShot 2024-07-05 at 17 49 12

Environment (please complete the following information):

mareksed commented 6 days ago

I looked into sources and sort of did quick fix, we can observe position change of the trigger

In flyoutReducer, I have changed

        case "position":
            if (state.status !== "rendered" && state.status !== "visible") return state;
            return {
                ...state,
                status: state.status === "visible" ? "visible" : "positioned",
                position: action.payload.position,
                styles: { ...defaultStyles, ...action.payload.styles },
            };

And in FlyoutControlled

      const MObserver = React.useRef(
        new MutationObserver((mutations) => {
            if (mutations.length) {
                updatePosition();
            }
        })
    );

    React.useEffect(() => {
        if (triggerElRef.current) {
            MObserver.current.observe(triggerElRef.current, { attributes: true });
        }
    }, [updatePosition, triggerElRef]);