EasyUI Forum
May 14, 2024, 12:31:11 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: MenuButton example issues  (Read 4127 times)
chrwei
Full Member
***
Posts: 219


View Profile Email
« 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?
Logged
chrwei
Full Member
***
Posts: 219


View Profile Email
« Reply #1 on: August 12, 2019, 12:55:05 PM »

I worked it out, the onMenuItemClick prop needs to be on MenuButton, not on Menu.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!