From f9261576d3c452b6a9466995b2a2caaa455ed162 Mon Sep 17 00:00:00 2001 From: guifu Date: Sat, 5 May 2018 15:59:41 +0800 Subject: [PATCH] fix: passing onclick through --- examples/antd.js | 32 +++++++++++++---------- src/SubMenu.jsx | 4 +-- src/SubPopupMenu.js | 5 ++-- tests/MenuItem.spec.js | 4 --- tests/__snapshots__/MenuItem.spec.js.snap | 2 -- 5 files changed, 21 insertions(+), 26 deletions(-) diff --git a/examples/antd.js b/examples/antd.js index 7b20e2cb..53972c86 100644 --- a/examples/antd.js +++ b/examples/antd.js @@ -11,6 +11,10 @@ function handleSelect(info) { console.log(`selected ${info.key}`); } +function handleItemClick(e) { + console.log('item clicked'); +} + const animation = { enter(node, done) { let height; @@ -52,24 +56,24 @@ const animation = { const reactContainer = document.getElementById('__react-content'); const nestSubMenu = (offset sub menu 2} key="4" popupOffset={[10, 15]}> - inner inner + inner inner sub menu 3} > - inner inner - inner inner2 + inner inner1 + inner inner2 - inn + inner inner3 sub menu 4} key="4-2-2"> - inner inner - inner inner2 + inner inner4 + inner inner5 - inner inner - inner inner2 + inner inner6 + inner inner7 ); @@ -77,16 +81,16 @@ const nestSubMenu = (offset sub menu 2} key="4" pop function onOpenChange(value) { console.log('onOpenChange', value); } -const commonMenu = ( +const commonMenu = ( sub menu} key="1"> - 0-1 - 0-2 + 0-1 + 0-2 {nestSubMenu} - 1 - outer + 1 + outer disabled - outer3 + outer3 ); function render(container) { diff --git a/src/SubMenu.jsx b/src/SubMenu.jsx index 1fce204c..7a5c5dd5 100644 --- a/src/SubMenu.jsx +++ b/src/SubMenu.jsx @@ -12,7 +12,6 @@ import { noop, loopMenuItemRecursively, getMenuIdFromSubMenuEventKey, - menuAllProps, } from './util'; let guid = 0; @@ -490,9 +489,8 @@ export class SubMenu extends React.Component { forceSubMenuRender, subMenuCloseDelay, } = props; - menuAllProps.forEach(key => delete props[key]); return ( -
  • +
  • {isInlineMode && title} {isInlineMode && children} {!isInlineMode && ( diff --git a/src/SubPopupMenu.js b/src/SubPopupMenu.js index 0fec13ab..0b0195ff 100644 --- a/src/SubPopupMenu.js +++ b/src/SubPopupMenu.js @@ -4,7 +4,7 @@ import { connect } from 'mini-store'; import KeyCode from 'rc-util/lib/KeyCode'; import createChainedFunction from 'rc-util/lib/createChainedFunction'; import classNames from 'classnames'; -import { getKeyFromChildrenIndex, loopMenuItem, noop, menuAllProps } from './util'; +import { getKeyFromChildrenIndex, loopMenuItem, noop } from './util'; import DOMWrap from './DOMWrap'; function allDisabled(arr) { @@ -327,12 +327,11 @@ export class SubPopupMenu extends React.Component { domProps.onKeyDown = this.onKeyDown; } const { prefixCls, eventKey, visible } = props; - menuAllProps.forEach(key => delete props[key]); return ( // ESLint is not smart enough to know that the type of `children` was checked. /* eslint-disable */ { expect(wrapper.render()).toMatchSnapshot(); wrapper.find('MenuItem').at(0).simulate('click'); expect(onClick).toHaveBeenCalledTimes(1); - wrapper.find('SubMenu').at(0).simulate('click'); - expect(onClick).toHaveBeenCalledTimes(2); - wrapper.find('MenuItemGroup').at(0).simulate('click'); - expect(onClick).toHaveBeenCalledTimes(3); }); }); diff --git a/tests/__snapshots__/MenuItem.spec.js.snap b/tests/__snapshots__/MenuItem.spec.js.snap index 86edeebe..17b307a5 100644 --- a/tests/__snapshots__/MenuItem.spec.js.snap +++ b/tests/__snapshots__/MenuItem.spec.js.snap @@ -34,9 +34,7 @@ exports[`MenuItem rest props can render all props to sub component 1`] = `