13

I am creating a simple icon drop-down menu using Material UI. But after rendering the glyph appears and no MenuItems are shown after clicking on the it. Here is the code -

import { IconMenu, IconButton } from 'material-ui' ;
const MoreVertIcon = require('material-ui/lib/svg-icons/navigation/more-vert');
const MenuItem = require('material-ui/lib/menus/menu-item');

const PostCard = React.createClass({
    render: function() {
        let button = (
                <IconButton
                    touch={true}
                    tooltip='Click to see menu.'
                    tooltipPosition='bottom-left'>
                    <MoreVertIcon />
                </IconButton>
            );
        return (
            <IconMenu iconButtonElement={button}>
                <MenuItem primaryText="Refresh" />
                <MenuItem primaryText="Send feedback" />
                <MenuItem primaryText="Settings" />
                <MenuItem primaryText="Help" />
                <MenuItem primaryText="Sign out" />
            </IconMenu>     
        );
    }
});
1
  • Did you find a solution to this? Having exactly the same problem here... Commented Nov 10, 2015 at 13:05

3 Answers 3

21

I had a similar issue. Solution was to to add this somewhere in the app. I'm not sure if it matters where but I added it at a higher-level as possible:

var injectTapEventPlugin = require("react-tap-event-plugin");
injectTapEventPlugin();
Sign up to request clarification or add additional context in comments.

1 Comment

just fyi. this has been fixed now with react v16+. no need to add these statements. Having these lines may actually slow down the click response to the user.
5

Just wanted to add the reason to add injectTapEventPlugin.

According to 300ms tap delay, gone away By Jake Archibald

Browsers stopped waiting 300ms for double taps and react's onClick doesnt give us the proper handle.

and According to react-tap-event-plugin git page

Facebook is not planning on supporting tap events (#436) because browsers are fixing/removing the click delay. Unfortunately it will take a lot of time before all mobile browsers (including iOS' UIWebView) will and can be updated.

Thats why we need to inject the plugin. About the proper solution, I decided to add the package and inject it in the App's constructor (The higer level I have).

The import:

import injectTapEventPlugin from 'react-tap-event-plugin';

And inside the constructor:

injectTapEventPlugin();

9 Comments

Best answer IMO
If you use React +16.4 you don't need to add the plugin. Just add in the package.json dependencies:"react": "16.4.0", "react-dom": "16.4.0"
after updating react to 16.13 i need deleted this plugin. but after it drop down menu not work.
@romanown can you please elaborate? This should have been resolved in React 16 and higher.
i have project where used var injectTapEventPlugin = require("react-tap-event-plugin"); injectTapEventPlugin(); after update the react from 15.4 to 16.13 i have error. in SO i find need delet this plugin. i deletit this. error is go out. buh drop down menu not have work. i only deleted this 2 string var injectTapEventPlugin = require("react-tap-event-plugin"); injectTapEventPlugin(); may be i need to edit my other the code? i to try v4 the material-ui
|
1

In my case I have to add injectTapEventPlugin as well as change handler.

var injectTapEventPlugin = require("react-tap-event-plugin");
const DropDownMenu = require('material-ui/lib/drop-down-menu');

...

injectTapEventPlugin(); // in constructor 

...

  handleChange(event, selectedIndex, menuItem) {
    this.setState({menu: event.target.value });
  }

...
  // in render
  let menuItems = [
       { payload: '0', text: 'Mon - Sun' },
       { payload: '1', text: 'Mon - Sat' },
       { payload: '2', text: 'Mon - Fri' },
       { payload: '3', text: 'Mon - Fri / Mon - Thu' },
    ];
...
  // in render return

  <DropDownMenu menuItems={menuItems} selectedIndex={this.state.menu} onChange={this.handleChange} /> 

1 Comment

how to do this if we have 2 dropdown with same content?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.