-
Notifications
You must be signed in to change notification settings - Fork 724
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
Input in Portal can't be focused inside Dialog #922
Comments
Hi @yyz945947732 👋 Please can you help us understand what your use-case is? Why do you need to portal an input out of the |
Hi, thanks for the reply. I want to render a custom Popover component inside Dialog. This Popover is portal to Is there any way to prevent the focus of elements outside the dialog that uses the portal from being trapped? |
Is there any particular reason it needs to be a "custom" popover components and you can't use radix's |
I do plan to refactor this component with radix, but it will take time, so I want to find a temporary solution. So is it appropriate to say that it is not the best practice to use radix with other component libraries, because it may cause some weird problems? At present, to solve this problem can only use radix's popover? |
A There are a couple things you can do for now to get this some of the way there.
Example: https://codesandbox.io/s/relaxed-joliot-mu48b?file=/src/App.js Or:
Example: https://codesandbox.io/s/staging-bird-pkglq?file=/src/App.js Or don't use the @benoitgrelard I am wondering though why our |
Yes, it's because we allow other focus scopes to take focus, this is done via a stack we manage internally. |
Instead of only allowing other focus scopes to take focus though, could we allow anything in the same React tree to take focus? |
We don't really specifically allow other focus scopes to take focus, it's rather that when a new focus scope mounts anywhere, it will deactivate the one that's active, and take over, then when it unmounts, the previous one will be reactivated. The reason it's not working within the react tree is because the code that handles containment is using dom events + We could take another look though. |
I have tried this before like: // Popover.tsx
const containerObjectRef = React.useRef<HTMLElement>(document.body);
React.useLayoutEffect(() => {
const triggerParentElement = triggerDOMElement?.parentElement;
if (triggerParentElement) {
containerObjectRef.current = triggerParentElement;
}
}, [triggerDOMElement]);
return <Portal containerRef={containerObjectRef}>{content}</Portal> but finally gave up this solution because it would cause zindex problems. Since it is not mounted on Example: https://codesandbox.io/s/hardcore-goldstine-bdllk?file=/App.js
I'm sorry. Set BTW, thank you for the fast response and for taking a deeper look at this issue. |
No worries. I'm not sure of an alternative workaround in the meantime in that case so we can look into React tree support when we have some time. Thanks for taking the time to help us understand the issue 🙂 EDIT: I just thought though, you could use our The |
Thank you so much. And I have seen similar problems with other libraries recently, I don't know if these can give some help: https://github.com/theKashey/react-focus-lock/blob/master/src/Trap.js#L144-L156 There may be an solution here is if But I know that the way radix manages focus is more complicated, because it supports more features than other libraries. So I don’t know if these can help a bit. |
https://codesandbox.io/s/focused-platform-2itl5?file=/App.js
A element which use Portal inside Dialog will cant't be focused and have style with 'pointer-events : none'. What can i do to solve it?
The text was updated successfully, but these errors were encountered: