question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ClickAwayListener triggered by descendant Select

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

13reactions
oliviertassinaricommented, 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

0reactions
oliviertassinaricommented, Mar 31, 2020

Duplicate of #18586

Read more comments on GitHub >

github_iconTop Results From Across the Web

ClickAwayListener triggered by descendant Select #13216
I have a Select component which is a descendant of a ClickAwayListener component. Clicking on one of the MenuItem s triggers the callback...
Read more >
React Popper with ClickAwayListener triggers onClick of all ...
Since my comment solved the problem, hence, I'll post it as an answer. Kindly change your onClick to onClick={() => deleteNotification()} .
Read more >
ClickAwayListener, Check the render method of ClickAwayListener ...
When an option in Select is chosen the ClickAwayListener triggers the callback, despite Select being its descendant. ClickAwayListener is a parent of ...
Read more >
How to Detect a Click Outside an Element - W3docs
Consequently, the main loop will go up the DOM from the clicked target element to search if the ancestor of that element belongs...
Read more >
Creating An Outside Focus And Click Handler React Component
In this article, we'll look at how to create an outside focus and click handler with React. We will recreate an open source...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found