-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
How to get ref to DOM element of Menus/Popovers #14342
Comments
Could you add example code? I think we should work on fixing this with the Manipulating the DOM sounds like drilling through the abstraction to control a specific behavior that might cause other parts of the component to fail. |
@jedwards1211 Is this related to #14345? If we resolve #14345 can we close this issue? |
There's no React-only way to determine if the |
And I'm absolutely not talking about manipulating the DOM, I'm talking about the read-only operation of determining whether |
@jedwards1211 I guess #13722 would solve this? It would enable |
Ah yes, that would solve it! |
Just in case someone got in here looking for a way to scroll to a particular item in the I spent over 2-3 hours on this issue, I was wondering where the refs was going. My thought was MUI wasn't passing the ref. Anyways I still love material ui and am a dead end fan for live, @oliviertassinari thank you for all your hard work (including the whole mui team of course) ;) |
@rotimi-best This is likely because of the portal behavior. I have seen this in some of the core components. What you can do is trigger the scroll only once the ref resolves, not on a setTimeout. |
@oliviertassinari oh that's cool, I tried googling it but couldn't find it. How do I know when a ref resolves in a function (like in a useEffect or a prop function)? |
I'm trying to make
material-ui-popup-state
'sbindHover
keep the popover open while either the anchor element or the menu or popover is hovered (jcoreio/material-ui-popup-state#3). I can't do this properly unless I can get a ref to the actual DOM element of the menu or popover.But with
findDOMNode
being deprecated, it seems like I'm screwed.Can't use
PaperProps={{ref: c => this.popover = c}}
, that gets a reference to a component instead of a DOM element.Paper
doesn't support any kind ofinnerRef
prop; I could pass it acomponent
that renders with theref
I need but that would be messy.To make matters worse, if I find the DOM element with the
id
I pass to the menu or popover, it's the container element that fills the whole screen rather than the menu/popover part. Same goes for thecurrentTarget
of event handlers passed to menu or popover.Maybe I can use
PaperProps={{ onMouseEnter: e => this.popover = e.currentTarget }}
, but the problem with that is the mouseenter event would come after the mouseleave on the anchor element.This sucks. I kind of hate that the React team doesn't want to allow us to find the root DOM node within a Component.
The text was updated successfully, but these errors were encountered: