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

select components: props appendTo Incorrect first time mount #5311

Closed
kl-nevermore opened this issue Nov 14, 2023 · 6 comments · Fixed by #5313, #5576 or #5717
Closed

select components: props appendTo Incorrect first time mount #5311

kl-nevermore opened this issue Nov 14, 2023 · 6 comments · Fixed by #5313, #5576 or #5717
Assignees
Labels
Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@kl-nevermore
Copy link
Contributor

kl-nevermore commented Nov 14, 2023

Describe the bug

when use appendTo ,the first time it was appended to the body, the second time it was mounted correctly

maybe all select components have this issue but Dialog ok

CascadeSelect

20231114155956_rec_

MultiSelect

20231114160553_rec_

Reproducer

https://codesandbox.io/s/primereact-demo-forked-tk9y7q?file=/src/D.js:53-59

PrimeReact version

10.0.9 and the master branch code

React version

17.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

Chrome 118

Steps to reproduce the behavior

No response

Expected behavior

If appendTo is an HTML element, should it be used for calculation?( like MultiSelect ? )
or
mounted correctly, the position does not change(like antd)

No response

@kl-nevermore kl-nevermore added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Nov 14, 2023
@kl-nevermore kl-nevermore changed the title appendTo Incorrect first time mount select components: props appendTo Incorrect first time mount Nov 14, 2023
@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Nov 14, 2023
melloware added a commit to melloware/primereact that referenced this issue Nov 14, 2023
@melloware melloware self-assigned this Nov 14, 2023
@melloware melloware added this to the 10.0.10 milestone Nov 14, 2023
nitrogenous added a commit that referenced this issue Nov 14, 2023
Fix #5311: AppendTo should be correct on mount
@melloware
Copy link
Member

@kl-nevermore please try 10.1.0 and confirm your issue is fixed.

@kl-nevermore
Copy link
Contributor Author

@kl-nevermore please try 10.1.0 and confirm your issue is fixed.

sorry! I just saw this message!
I'll test it when I get finish work

@kl-nevermore
Copy link
Contributor Author

@melloware melloware reopened this Dec 8, 2023
@github-actions github-actions bot added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 8, 2023
@melloware
Copy link
Member

Can you investigate?

What I fixed was in useMounteffect I set the overlay.

        useMountEffect(() => {
            alignOverlay();
        });

        const alignOverlay = () => {
            DomHandler.alignOverlay(overlayRef.current, labelRef.current.parentElement, props.appendTo || (context && context.appendTo) || PrimeReact.appendTo);
        };

So on Mount of the component the overlay should already be set to append to the correct spot where before it was waiting until it was shown the first time to appendTo?

@melloware melloware removed the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Dec 8, 2023
@melloware melloware removed this from the 10.1.0 milestone Dec 8, 2023
@kl-nevermore
Copy link
Contributor Author

kl-nevermore commented Dec 11, 2023

Whether use ref or selectors ,the appendTo always is nil

I have two solutions
1: use state instead

const ref = useRef();
const [refState, setRefState] = useState();
useEffect(() => {
  setRefState(ref.current);
}, []);
<div ref={ref}>append to</div>
<MultiSelect appendTo={refState} />;

2: appendTo support function

<MultiSelect appendTo={()=>ref.current} />;

@melloware
Copy link
Member

I like solution 2 above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
2 participants