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

ClickAwayListener triggered by descendant Select #13216

Closed
2 tasks done
pleopardi opened this issue Oct 12, 2018 · 6 comments
Closed
2 tasks done

ClickAwayListener triggered by descendant Select #13216

pleopardi opened this issue Oct 12, 2018 · 6 comments
Labels
component: ClickAwayListener The React component duplicate This issue or pull request already exists

Comments

@pleopardi
Copy link

I'm opening this issue because I saw the discussion here but the pull request closing the issue doesn't seem to apply to my case.

I have a Select component which is a descendant of a ClickAwayListener component. Clicking on one of the MenuItems triggers the callback of ClickAwayListener.

I saw the pull request adding disablePortal option but I couldn't find a way to apply it to Select (I saw it only in Popper and Modal components).

  • This is not a v0.x issue.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

ClickAwayListener callback shouldn't be triggered clicking on a descendant component.

Current Behavior

But it does and I can't find a way to apply the disablePortal fix to Select component. I'd like to avoid using native select to solve the issue.

Steps to Reproduce

Link:

  1. Basic Example

Context

I have a Collapse containing several filters which closes every time I select an item from the Select filter.

Your Environment

Project generated with create-react-app, not ejected.

Tech Version
Material-UI v3.1.2
React v16.5.2
Browser Chrome
TypeScript No
etc.
@oliviertassinari oliviertassinari added the support: question Community support but can be turned into an improvement label Oct 12, 2018
@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 13, 2018

@pleopardi Here is an example:

      <ClickAwayListener onClickAway={this.handleClickAway}>
        <Select
          value={this.state.selected}
          onChange={this.handleChange}
          MenuProps={{ disablePortal: true }}
        >
          <MenuItem value="first">First Option</MenuItem>
          <MenuItem value="second">Second Option</MenuItem>
        </Select>
      </ClickAwayListener>

https://codesandbox.io/s/qv6z7k32nw

@oliviertassinari oliviertassinari added the component: select This is the name of the generic UI component, not the React module! label Oct 13, 2018
@Teivaz
Copy link

Teivaz commented Dec 27, 2018

This only works with first child https://codesandbox.io/s/jzj7np639v
Is this expected?
The only notion of this in docs is that "The wrapped element" is referred to in singular.

Name Type Default Description
children * element   The wrapped element.
-- -- -- --

@oliviertassinari
Copy link
Member

@Teivaz Check the warning in the console:

capture d ecran 2018-12-27 a 20 22 04

We are aware of this limitation, it's documented. Now, going forward, we are waiting on reactjs/rfcs#97 to land so we can accept a node over an element:

  /**
-  * The wrapped element.
+  * The wrapped node.
   */
- children: PropTypes.element.isRequired,
+ children: PropTypes.node.isRequired,

@Teivaz
Copy link

Teivaz commented Dec 27, 2018

@octavioamu Thanks for clarification. I didn't see any warnings in my code and thought there was a bug in it. But after some investigation got it clear.

@Mishhub
Copy link

Mishhub commented Mar 31, 2020

Add
MenuProps={{ disablePortal: true }}
prop to Select component. This fixed mine
Just like mentioned here #13216 (comment)

@oliviertassinari oliviertassinari added duplicate This issue or pull request already exists and removed support: question Community support but can be turned into an improvement labels Mar 31, 2020
@oliviertassinari
Copy link
Member

oliviertassinari commented Mar 31, 2020

Duplicate of #18586

@oliviertassinari oliviertassinari marked this as a duplicate of #18586 Mar 31, 2020
@oliviertassinari oliviertassinari added component: ClickAwayListener The React component and removed component: select This is the name of the generic UI component, not the React module! labels Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ClickAwayListener The React component duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants