-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[ClickAwayListener] Triggers on Select (and more) #12034
Comments
@dnutels The Select portals the options to the end of the body element. You can't use the
|
@oliviertassinari So... custom |
@dnutels There is a Yeah, I don't think that we can do anything at the |
I'm having the same kind of problem: click on a Select option triggers ClickAwayListener and closes my Collapse, even though Select is a descendant of ClickAwayListener (not a direct child though). I saw the PR fixing the problem but I can't understand how it applies to Select component: I only see disablePortal prop in Modal and Popper components. |
Easy enough to work around this Add an id or some other identifier to the On the |
#13216 (comment)
|
Note that #18586 has a proposed solution to a builtin solution to the problem, it's up for a pull request :). |
Setting |
Thank you so much for your approach, it helped me work with mine. Here's what i did, maybe can help someone:
|
adding other case where we are using the onCLickAway function like this (getted from the Menu UI Demo doc page); const onClickAwayCallBack = (event) => {
if (anchorRef.current && anchorRef.current.contains(event.target)) {
return;
}
setOpen(false);
}; just we have to add the 'return' instead of 'event.preventDefault();' like this; const onClickAwayCallBack = (event) => {
if (event.target.localName === 'body') {
return;
}
if (anchorRef.current && anchorRef.current.contains(event.target)) {
return;
}
setOpen(false);
}; thank you @Pabriuz for the help |
Isn't this all solved now with [EDIT] - spoke too soon, also needed to check that clicks were on the backdrop and not the select contents: if (
target.localName === "div" &&
target?.className.indexOf("MuiBackdrop-root") > -1
) {
setSelectOpen(false);
} |
Muito obrigado, funcionou pra mim. |
if (event.target.localName === 'body') { |
It worked for me, save my life |
This is best explained using code.
The following example is constructed by copy/pasting code form the docs and combining
ClickAwayListener
andSelect
.When an option in
Select
is chosen theClickAwayListener
triggers the callback, despiteSelect
being its descendant.Expected Behavior
Select
should normally close with the chosen value being the current in theSelect
and the click-away trigger shouldn't fire.Current Behavior
When an option in
Select
is chosen theClickAwayListener
triggers the callback, despiteSelect
being its descendant.Steps to Reproduce (for bugs)
See codesandbox: https://codesandbox.io/s/3qq7l6478m, forked from the one in docs: https://codesandbox.io/s/6llvjywwq3
Context
I have a
Select
in aDrawer
that contains a form. TheDrawer
hasClickAwayListener
enveloping its content, includingSelect
.When a value is chosen in
Select
, the click-away trigger is executed (and it closes theDrawer
in my app).Your Environment
The text was updated successfully, but these errors were encountered: