-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
[IconMenu] Support MenuItem nested menuItems #3265
Conversation
Thanks for your PR! 👍 https://github.com/callemall/material-ui/blob/master/CONTRIBUTING.md |
this.close(isKeyboard ? 'enter' : 'itemTap', isKeyboard); | ||
}, this.props.touchTapCloseDelay); | ||
|
||
if (this.props.onItemTouchTap > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this line. That's not supposed to be a number.
onItemTouchTap: React.PropTypes.func,
Try that, hopefully I haven't got the wrong object this time. |
|
||
const descriptions = { | ||
simple: 'Simple Icon Menus demonstrating some of the layouts possible using the `anchorOrigin` and `' + | ||
'targetOrigin` properties.', | ||
controlled: 'Two controlled examples, the first allowing a single selection, the second multiple selections.', | ||
scrollable: 'The `maxHeight` property limits the height of the menu, above which it will be scrollable.', | ||
nested: 'Example of nested menus within a icon menu.', | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"an Icon Menu" (or "an IconMenu
") - I'm still never sure which, despite the fact I wrote all those descriptions. 😄
Icon Menu to refer to the feature, IconMenu
to refer to the React component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I think whenever we're mentioning another component we should use the component name with back ticks.
`IconMenu`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you like me to change the description? To IconMenu
then?
I'm wondering if this can be achieved without the extra prop? What is Menu / MenuItem doing for nested menus? |
@mbrookes I'm not using an extra prop, the prop was already there and when you set it to less than 1 then with the original code the menu just disappears, which is useless if you have nested menus as the main menu disappears before you can click on the nested menu. In the project I am working on that uses this library we have a very deep context menu if we have it all in a one level drop down then it easily goes of the bottom of the screen, so using nested menus is a must. |
iconButtonElement={<IconButton><MoreVertIcon/></IconButton>} | ||
anchorOrigin={{horizontal: 'left', vertical: 'top'}} | ||
targetOrigin={{horizontal: 'left', vertical: 'top'}} | ||
touchTapCloseDelay={-1} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about touchTapCloseDelay={0}
?
However, that sounds like a hack
.
I agree, I think that we should be checking for a |
Updated with the feedback. Let me know if anything else needs changing. |
@@ -13,12 +13,15 @@ import IconMenuExampleControlled from './ExampleControlled'; | |||
import iconMenuExampleControlledCode from '!raw!./ExampleControlled'; | |||
import IconMenuExampleScrollable from './ExampleScrollable'; | |||
import iconMenuExampleScrollableCode from '!raw!./ExampleScrollable'; | |||
import IconMenuExampleNested from './ExampleNestedDrop'; | |||
import iconMenuExampleNestedCode from '!raw!./ExampleNestedDrop'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you call the file ExampleNested.jsx
please.
@tomrosier I haven't tested it, but that looks great from a diff point of view 👍. |
<MenuItem primaryText="Propercase" />, | ||
]} | ||
/> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about add a MenuItem
without a menuItems
property in this example?
@tomrosier That looks good to me. Could you squash down the commits and have a look at my comment? |
|
||
const descriptions = { | ||
simple: 'Simple Icon Menus demonstrating some of the layouts possible using the `anchorOrigin` and `' + | ||
'targetOrigin` properties.', | ||
controlled: 'Two controlled examples, the first allowing a single selection, the second multiple selections.', | ||
scrollable: 'The `maxHeight` property limits the height of the menu, above which it will be scrollable.', | ||
nested: 'Example of nested menus within a IconMenu.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"an IconMenu
"
…they would close instantaneously Made my changes comply with the lint standards Changed onItemTouchTap to touchTapCloseDelay, as accidentally chose wrong one. added the ability for the icon-menu to detect if any of the sub items contain submenus Updated with changes from @oliviertassinari and @mbrookes Renamed a file updated the examples, and corrected spelling
That looks good to me 👍. |
This is great 👍 Thanks a lot 😁 |
[IconMenu] Support MenuItem nested menuItems
I have a very similar requirement, and using the 'children' prop of menuItems almost works for my leftNav menu items. Using redux, I am passing in an Immutable Map (and ignoring the React warning). As you can see, it does make the indented children. However, it puts them ABOVE the primaryText vs below them. Is there something I'm doing wrong, or (1) we should have a config to specify children location or (2) children should be below primaryText? Thanks! render() {
let me = this,
getSubItems = (subItems) => {
if(!subItems) return null;
return subItems.map(function(subItem, key) {
let subName = subItem.get('name'),
subKey = 'sub' + key;
if(EnableConsoleLog) console.log('subName: ', subName);
return (<MenuItem
key={subKey}
primaryText={subName}
onTouchTap={me.handleToggle.bind(me)}
/>)
});
},
menuItems = me.props.menuItems.map(function(menuItem, key) {
let name = menuItem.get('name'),
subItems = menuItem.get('subItems');
if(EnableConsoleLog) console.log('name: ', name);
return (<MenuItem
key={key}
primaryText={name}
onTouchTap={me.handleToggle.bind(me)}
insetChildren={true}
children={getSubItems(subItems)}
/>)
});
return (
<div id="my-page-container">
<LeftNav
ref="leftNav"
docked={false}
open={me.state.open}
children={menuItems}
/>
<AppBar title='React Reflux Material UI' onLeftIconButtonTouchTap={me.handleToggle.bind(me)}/>
<div style={styles.container}>
I am the app component with mui
</div>
</div>
)
} store.dispatch({
type: 'SET_STATE',
state: {
uiState: {
aKey: 'aValue'
},
domainState: {
menuItems: {
lastViewed: {
name: 'Recent Items',
subItems: {
salesOrders: {
name: 'Pythons'
},
creditMemos: {
name: 'Penguins'
}
}
},
dashboard: {
name: 'Dashboard'
},
sales: {
name: 'Animals',
subItems: {
customers: {
name: 'Puppies'
},
salesOrders: {
name: 'Parakeets'
},
shipments: {
name: 'Pythons'
},
customerInvoices: {
name: 'Parrots'
},
creditMemos: {
name: 'Peacocks'
},
customerReceipts: {
name: 'Penguins'
}
}
},
financials: {
name: 'Mordant'
},
allPages: {
name: 'All Pages'
}
}
}
}
}); |
@Dreculah Are you using OrderedMap? because Map doesn't guarantee order. |
@alitaheri This logic is not contingent on sorting, since there will only be subMenu items produced produced and added as children for an object with subItems. I also see the expected console.log messages and as you can see below the DOM is built with the expected nesting (pythons and penguins as subItems of Recent Items), but not rendered as such... |
Please try toJS() if that fixes it it's react, if not it's us O.o |
I switched from a hash map to array so I could use toJS() for map iteration, and I still see exactly the same problem. Unfortunately, I don't know the material-ui & react source code yet, so I can't spot the problem straight away. It is odd that the React DOM would have the expected structure, but not the browser DOM. |
Yeah exactly! This is really surprising to me! Can you reproduce this using a very simple array? |
The array is pretty simple now (please see below). Maybe its a React bug? menuItems: [
{
name: 'Recent Items',
subItems: [
{
name: 'Pythons'
},
{
name: 'Penguins'
}
]
},
{
name: 'Dashboard'
},
{
name: 'Animals',
subItems: [
{
name: 'Puppies'
},
{
name: 'Parakeets'
},
{
name: 'Pythons'
},
{
name: 'Parrots'
},
{
name: 'Peacocks'
},
{
name: 'Penguins'
}
]
},
{
name: 'Mordant'
},
{
name: 'All Pages'
}
] |
it cannot be a bug with react. and I can't reproduce this on my end. any chance you can write a small failing test so we can make it pass? I looked at the code, if there is anything wrong it's not related to this PR anyway as it,s not where the logic actually happens. So it's going to be hard to fix. A failing test will be the fastest way to squeeze out this bug. And make sure it will never happen again 👍 |
OK, thanks! I've asked one of my teammates to have a go at this. |
That's great news. thank you and your teammate for looking into this 👍 👍 |
Thank you for material-ui! |
You should thank callemall and @hai-cea, I'm just a simple collaborator 😅 But I'm really glad this project is helping your company 👍 👍 |
Hi @alitaheri , I’m working with @Dreculah . I have created 2 failing test cases for the |
@cfkenandy Wow that's awesome thank you 👍 any chance you can turn that zip into a PR so that others can check it out with ease? That would be awesome. 😍 |
@alitaheri , You mean I should create a branch from https://github.com/callemall/material-ui/ and then create a PR? |
@cfkenandy You should |
Thanks! Am on it. |
@alitaheri Hope I got this right. #3573 |
@cfkenandy Yes you did. thank you 👍 👍 |
If nested
menuItem
is used inMenuItem
they close instantaneously.This is an example of the bug. http://imgur.com/g4M32q4