EasyUI Forum

General Category => EasyUI for React => Topic started by: chrwei on July 31, 2019, 02:08:10 PM



Title: MenuButton example issues
Post by: chrwei on July 31, 2019, 02:08:10 PM
I'm having problems getting onItemClick working.  as a test, I've ran create-react-app to make a new project and replaced App.js with the following based on your MenuButton live demo.

Code:
import React from 'react';
import { Menu, MenuButton, MenuItem } from 'rc-easyui';


class App extends React.Component {

  TestMenu() {
    function handleClick(val) {
      console.log(val);
      alert(val);
    }
    return (
      <Menu onItemClick={handleClick.bind(this)}>
        <MenuItem text="Add" value="add"></MenuItem>
        <MenuItem text="Delete" value="delete"></MenuItem>
      </Menu>
    );
  }

  render() {
    return (
      <div>
        <MenuButton text="Edit" plain iconCls="icon-edit" menu={this.TestMenu}></MenuButton>
      </div>
    );
  }
}
 
export default App;

the button and menu renders fine, but I get no alert and no console log no matter where or what I click.  I've tried every permutation of handleClick I can think of and either get understandable errors or no output.  what's the right way to handle the item click and get the value?


Title: Re: MenuButton example issues
Post by: chrwei on August 12, 2019, 12:55:05 PM
I worked it out, the onMenuItemClick prop needs to be on MenuButton, not on Menu.