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

New Components Menu and MenuItem doesn't work

Open eyscode opened this issue 11 years ago • 16 comments

I've tried to use the new components Menu and MenuItem in a project as the website shows but I couldn't, when the component is rendered the menu is not visible and width is always 0, I thought it was a problem with styles of my project, so I tried to use it in clean tiny example just for seeing if it works or not, and sadly it doesn't.

This is the code:

var React = require('react');
var Menu = require('material-ui/lib/menus/menu');
var MenuItem = require('material-ui/lib/menus/menu-item');
var ThemeManager =  require('material-ui/lib/styles').ThemeManager;
var themeManager = new ThemeManager();

var styles = {
    menu: {
        marginRight: 32,
        marginBottom: 32,
        float: 'left',
        position: 'relative',
        zIndex: 0
    }
};

var App = React.createClass({
    contextTypes: {
        router:React.PropTypes.func
    },
    childContextTypes: {
        muiTheme:React.PropTypes.object
    },
    getChildContext:function() {
        return {
                muiTheme: themeManager.getCurrentTheme()
        };
    },
    render: function(){
    return (
        <Menu style={styles.menu}>
          <MenuItem primaryText="Maps" />
          <MenuItem primaryText="Books" />
          <MenuItem primaryText="Flights" />
          <MenuItem primaryText="Apps" />
        </Menu>);
    }

});

React.render(<App/>, document.getElementById('app'));

As you can see it is the almost the same code as the example in the website demo, but the menu is not visible. What's the problem? Are the new Menu and MenuItem components already finished and ready for production? Thanks in advance.

eyscode avatar Jul 21 '15 22:07 eyscode

I'm getting the same problem here. The component is rendered but not visible

inoc603 avatar Jul 22 '15 09:07 inoc603

:+1: Same is happening here

vespakoen avatar Jul 22 '15 14:07 vespakoen

:+1:

micaste avatar Jul 22 '15 16:07 micaste

Same for ListItem, the component is rendered but not visible.

zachguo avatar Jul 22 '15 22:07 zachguo

Well, it's working after I upgraded material-ui to latest version.

zachguo avatar Jul 22 '15 22:07 zachguo

@zachguo what last version do you talk about ? I encounter the bug mentioned by @eyscode with version 0.10.1 that is for now the latest released version.

micaste avatar Jul 23 '15 14:07 micaste

@zachguo List and ListItem works fine in the latest version, I've even had to use those component instead of Menu and MenuItem because the bug.

eyscode avatar Jul 23 '15 16:07 eyscode

I've got a log in the console: Uncaught TypeError: Cannot read property 'length' of undefined it points to this line of the source file(menu.js) for (var i = 0; i < this.props.menuItems.length; i++) {

ieiayaobb avatar Jul 24 '15 05:07 ieiayaobb

It seems like you are using the old Menu and MenuItem components, I saw the same error log when I imported those components by mistake.

Old components:

import {Menu, MenuItem} from 'material-ui';

New components:

import Menu from 'material-ui/lib/menus/menu';
import MenuItem from 'material-ui/lib/menus/menu-item';

Anyway the new ones don't work properly, so I suggest using List and ListItem for now.

eyscode avatar Jul 24 '15 07:07 eyscode

@eyscode I tried as you said, same problem with you have described. I'm going to use List instead.

Anyway thanks for your advice.

ieiayaobb avatar Jul 24 '15 07:07 ieiayaobb

I've updated to the latest version of material-ui (v0.10.3) and the new Menu component works fine now. It seems like the bug was fixed in #1281. I'm closing the issue, thanks for your time.

eyscode avatar Aug 14 '15 04:08 eyscode

this is still a problem. When you

import {Menu, MenuItem} from 'material-ui'; 

it's still referencing the old material-ui/lib/menu/menu.js

cvince avatar Oct 16 '15 19:10 cvince

I am still seeing this problem with the latest Master branch build.

This results in a length undefined error

import {Menu, MenuItem, MenuDivider} from 'material-ui';

This results in an invisible menu:

import Menu from 'material-ui-updated/lib/menus/menu';
import MenuItem from 'material-ui-updated/lib/menus/menu-item';

austinmao avatar Nov 17 '15 07:11 austinmao

Dear developers! Please, update your documentation!

`Cuz i had the same stack

AtNovember avatar Aug 26 '16 12:08 AtNovember

Is there solution, please? I have same problem.

ingridoberbuchler avatar Oct 04 '16 11:10 ingridoberbuchler

Problem still, Any solution?

ivanberry avatar Jul 22 '17 02:07 ivanberry