material-ui icon indicating copy to clipboard operation
material-ui copied to clipboard

[MenuItem] SubItem Collapsing when setState is called in container

Open KevinMongiello opened this issue 9 years ago • 7 comments

Problem description

I'm constrained to build a nested popover menu in my render method. And every time I setState ( and render a new menu) The popover behaves differently based on which nested MenuItem I have open.

Each has a nested array of Checkbox inputs. When a checkbox is clicked, it sets state in the container (required In my app in order to control checkboxes). The first group of subItems (Menu Item 1) will remain open when checking the checkbox, any additional groups (Menu Item 2-4 +) automatically close on checking the checkbox.

Link to minimally-working code that reproduces the issue

I've linked a code example. Please click the button labeled "Click Me", then open up each menuItem's subMenus, and try and click (directly) on the input/checkbox. The first submenu will remain open and the rest of them will close onTouchTap event. I've tried including several other event handlers to prevent default on and none work.

WebpackBin: http://www.webpackbin.com/4kX-28iDz

Versions

  • Material-UI: "0.16.7",
  • React: "15.4.2"
  • Browser: 55.0.2883.95 (64-bit)

KevinMongiello avatar Feb 01 '17 23:02 KevinMongiello

I spent a decent amount of time trying to figure out what is causing this, but could not find an answer. I believe it's specifically related to the interaction between using a Checkbox component for the primaryText attribute.

Ultimately, the currently implemented API is to close on click (see this line in MenuItem). I checked this is consistent across menu items and it is (see this WebpackBin)

mattste avatar Feb 06 '17 06:02 mattste

Do you know how I could keep the menu open through click events? I need nested dropdown menu to stay open so I can click multiple checkboxes. Or do you have any suggestion how to create a similar feature with other components?

KevinMongiello avatar Feb 06 '17 16:02 KevinMongiello

@KevinMongiello event.stopPropagation?

mbrookes avatar Feb 06 '17 18:02 mbrookes

@mbrookes Doesn't work. I included that in the onTouchTap handler for the checkboxes in the WebpackBin with no avail.

KevinMongiello avatar Feb 06 '17 18:02 KevinMongiello

@KevinMongiello This may be related to #5104

mattste avatar Feb 14 '17 04:02 mattste

@mattste Yeah It very well might be, I remember reading that thread but it doesn't look like there was any real resolution since under certain circumstances the checkboxes appear to respond to preventDefault / stopPropagation

KevinMongiello avatar Feb 14 '17 04:02 KevinMongiello

We have been porting the component on the v1-beta branch. We reimplemented it from the ground-up. While we haven't tested it, I think that the issue is most likely fixed on that branch. Hence, I'm closing it. Still, we will accept PR fixes until v1-beta takes over the master branch.

oliviertassinari avatar Aug 05 '17 06:08 oliviertassinari