From 2b4b08e4c25b38a9363da5745b2bf03bb80b9b23 Mon Sep 17 00:00:00 2001 From: jljsj33 Date: Fri, 20 Apr 2018 13:57:52 +0800 Subject: [PATCH 01/16] inherit props --- src/MenuItem.jsx | 19 ++++++++++++++++++- src/MenuItemGroup.jsx | 9 +++++++-- src/SubMenu.jsx | 28 +++++++++++++++++++++++++--- src/SubPopupMenu.js | 25 +++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 6 deletions(-) diff --git a/src/MenuItem.jsx b/src/MenuItem.jsx index 3920b7b5..32823dfa 100644 --- a/src/MenuItem.jsx +++ b/src/MenuItem.jsx @@ -139,7 +139,7 @@ export class MenuItem extends React.Component { } render() { - const props = this.props; + const props = { ...this.props }; const className = classNames(this.getPrefixCls(), props.className, { [this.getActiveClassName()]: !props.disabled && props.active, [this.getSelectedClassName()]: props.isSelected, @@ -161,6 +161,22 @@ export class MenuItem extends React.Component { onMouseEnter: this.onMouseEnter, }; } + [ + 'rootPrefixCls', + 'eventKey', + 'active', + 'selectedKeys', + 'disabled', + 'title', + 'onItemHover', + 'onSelect', + 'onClick', + 'onDeselect', + 'parentMenu', + 'onDestroy', + 'onMouseEnter', + 'onMouseLeave', + ].forEach(key => delete props[key]) const style = { ...props.style, }; @@ -169,6 +185,7 @@ export class MenuItem extends React.Component { } return (
  • delete props[key]); return ( -
  • +
  • triggerNode.parentNode; const popupPlacement = popupPlacementMap[props.mode]; const popupClassName = props.mode === 'inline' ? '' : props.popupClassName; - + [ + 'parentMenu', + 'title', + 'selectedKeys', + 'openKeys', + 'onClick', + 'onOpenChange', + 'rootPrefixCls', + 'eventKey', + 'multiple', + 'active', + 'onItemHover', + 'onSelect', + 'triggerSubMenuAction', + 'onDeselect', + 'onDestroy', + 'onMouseEnter', + 'onMouseLeave', + 'onTitleMouseEnter', + 'onTitleMouseLeave', + 'onTitleClick', + 'isOpen', + ].forEach(key => delete props[key]); return ( -
  • +
  • {isInlineMode && title} {isInlineMode && children} {!isInlineMode && ( diff --git a/src/SubPopupMenu.js b/src/SubPopupMenu.js index 7bcecb5b..04d6f28b 100644 --- a/src/SubPopupMenu.js +++ b/src/SubPopupMenu.js @@ -6,6 +6,7 @@ import createChainedFunction from 'rc-util/lib/createChainedFunction'; import classNames from 'classnames'; import { getKeyFromChildrenIndex, loopMenuItem, noop } from './util'; import DOMWrap from './DOMWrap'; +import { collapseTextChangeRangesAcrossMultipleVersions } from 'typescript'; function allDisabled(arr) { if (!arr.length) { @@ -311,7 +312,31 @@ export class SubPopupMenu extends React.Component { props.className, `${props.prefixCls}-${props.mode}`, ); + [ + 'defaultSelectedKeys', + 'selectedKeys', + 'defaultOpenKeys', + 'openKeys', + 'mode', + 'getPopupContainer', + 'onClick', + 'onSelect', + 'onDeselect', + 'onDestroy', + 'openTransitionName', + 'openAnimation', + 'subMenuOpenDelay', + 'subMenuCloseDelay', + 'forceSubMenuRender', + 'triggerSubMenuAction', + 'level', + 'selectable', + 'multiple', + 'onOpenChange', + 'visible', + ].forEach(key => delete props[key]); const domProps = { + ...props, className, role: 'menu', 'aria-activedescendant': '', From 573c1d149665b988b627e5cad9211b81e3bbba53 Mon Sep 17 00:00:00 2001 From: jljsj33 Date: Fri, 20 Apr 2018 13:59:36 +0800 Subject: [PATCH 02/16] update --- src/SubPopupMenu.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/SubPopupMenu.js b/src/SubPopupMenu.js index 04d6f28b..b04cd166 100644 --- a/src/SubPopupMenu.js +++ b/src/SubPopupMenu.js @@ -6,7 +6,6 @@ import createChainedFunction from 'rc-util/lib/createChainedFunction'; import classNames from 'classnames'; import { getKeyFromChildrenIndex, loopMenuItem, noop } from './util'; import DOMWrap from './DOMWrap'; -import { collapseTextChangeRangesAcrossMultipleVersions } from 'typescript'; function allDisabled(arr) { if (!arr.length) { From 47b0b64985ab63d9364a21eb7d9cdafaf0bcc8d6 Mon Sep 17 00:00:00 2001 From: jljsj33 Date: Fri, 20 Apr 2018 14:05:29 +0800 Subject: [PATCH 03/16] update --- src/SubPopupMenu.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SubPopupMenu.js b/src/SubPopupMenu.js index b04cd166..11bd65f2 100644 --- a/src/SubPopupMenu.js +++ b/src/SubPopupMenu.js @@ -311,6 +311,7 @@ export class SubPopupMenu extends React.Component { props.className, `${props.prefixCls}-${props.mode}`, ); + const focusable = props.focusable; [ 'defaultSelectedKeys', 'selectedKeys', @@ -333,6 +334,8 @@ export class SubPopupMenu extends React.Component { 'multiple', 'onOpenChange', 'visible', + 'focusable', + 'defaultActiveFirst', ].forEach(key => delete props[key]); const domProps = { ...props, @@ -343,7 +346,7 @@ export class SubPopupMenu extends React.Component { if (props.id) { domProps.id = props.id; } - if (props.focusable) { + if (focusable) { domProps.tabIndex = '0'; domProps.onKeyDown = this.onKeyDown; } From ae9fd6cf63a33974f4fddda76f4c784c31586626 Mon Sep 17 00:00:00 2001 From: jljsj33 Date: Fri, 20 Apr 2018 14:11:38 +0800 Subject: [PATCH 04/16] update menu props mixin --- src/SubPopupMenu.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/SubPopupMenu.js b/src/SubPopupMenu.js index 11bd65f2..cb9a3f09 100644 --- a/src/SubPopupMenu.js +++ b/src/SubPopupMenu.js @@ -336,6 +336,8 @@ export class SubPopupMenu extends React.Component { 'visible', 'focusable', 'defaultActiveFirst', + 'prefixCls', + 'inlineIndent', ].forEach(key => delete props[key]); const domProps = { ...props, From 3559f835bb9bfd250923a6f57f9e401baa75df38 Mon Sep 17 00:00:00 2001 From: jljsj33 Date: Fri, 20 Apr 2018 14:14:44 +0800 Subject: [PATCH 05/16] update --- src/SubPopupMenu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SubPopupMenu.js b/src/SubPopupMenu.js index cb9a3f09..2881c810 100644 --- a/src/SubPopupMenu.js +++ b/src/SubPopupMenu.js @@ -356,11 +356,11 @@ export class SubPopupMenu extends React.Component { // ESLint is not smart enough to know that the type of `children` was checked. /* eslint-disable */ {React.Children.map( props.children, From 23b4bc37034531d2d971d3f54bed4450b0ab2b52 Mon Sep 17 00:00:00 2001 From: jljsj33 Date: Fri, 20 Apr 2018 14:16:04 +0800 Subject: [PATCH 06/16] update --- src/SubPopupMenu.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/src/SubPopupMenu.js b/src/SubPopupMenu.js index 2881c810..4bab00ca 100644 --- a/src/SubPopupMenu.js +++ b/src/SubPopupMenu.js @@ -311,7 +311,18 @@ export class SubPopupMenu extends React.Component { props.className, `${props.prefixCls}-${props.mode}`, ); - const focusable = props.focusable; + const domProps = { + className, + role: 'menu', + 'aria-activedescendant': '', + }; + if (props.id) { + domProps.id = props.id; + } + if (props.focusable) { + domProps.tabIndex = '0'; + domProps.onKeyDown = this.onKeyDown; + } [ 'defaultSelectedKeys', 'selectedKeys', @@ -339,28 +350,16 @@ export class SubPopupMenu extends React.Component { 'prefixCls', 'inlineIndent', ].forEach(key => delete props[key]); - const domProps = { - ...props, - className, - role: 'menu', - 'aria-activedescendant': '', - }; - if (props.id) { - domProps.id = props.id; - } - if (focusable) { - domProps.tabIndex = '0'; - domProps.onKeyDown = this.onKeyDown; - } return ( // ESLint is not smart enough to know that the type of `children` was checked. /* eslint-disable */ {React.Children.map( props.children, From 7def68f794de4638ae5de4e13a5747902187df95 Mon Sep 17 00:00:00 2001 From: jljsj33 Date: Fri, 20 Apr 2018 14:35:32 +0800 Subject: [PATCH 07/16] extract inherit props to util --- src/MenuItem.jsx | 19 ++-------------- src/MenuItemGroup.jsx | 7 ++---- src/SubMenu.jsx | 25 ++-------------------- src/SubPopupMenu.js | 30 ++------------------------ src/util.js | 50 +++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 56 insertions(+), 75 deletions(-) diff --git a/src/MenuItem.jsx b/src/MenuItem.jsx index 32823dfa..5ad2da35 100644 --- a/src/MenuItem.jsx +++ b/src/MenuItem.jsx @@ -5,7 +5,7 @@ import KeyCode from 'rc-util/lib/KeyCode'; import classNames from 'classnames'; import scrollIntoView from 'dom-scroll-into-view'; import { connect } from 'mini-store'; -import { noop } from './util'; +import { noop, menuInheritProps } from './util'; /* eslint react/no-is-mounted:0 */ @@ -161,22 +161,7 @@ export class MenuItem extends React.Component { onMouseEnter: this.onMouseEnter, }; } - [ - 'rootPrefixCls', - 'eventKey', - 'active', - 'selectedKeys', - 'disabled', - 'title', - 'onItemHover', - 'onSelect', - 'onClick', - 'onDeselect', - 'parentMenu', - 'onDestroy', - 'onMouseEnter', - 'onMouseLeave', - ].forEach(key => delete props[key]) + menuInheritProps.forEach(key => delete props[key]) const style = { ...props.style, }; diff --git a/src/MenuItemGroup.jsx b/src/MenuItemGroup.jsx index b6380701..0e30286e 100644 --- a/src/MenuItemGroup.jsx +++ b/src/MenuItemGroup.jsx @@ -1,5 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; +import { menuInheritProps } from './util'; class MenuItemGroup extends React.Component { static propTypes = { @@ -24,11 +25,7 @@ class MenuItemGroup extends React.Component { const { className = '', rootPrefixCls } = props; const titleClassName = `${rootPrefixCls}-item-group-title`; const listClassName = `${rootPrefixCls}-item-group-list`; - [ - 'renderMenuItem', - 'index', - 'rootPrefixCls', - ].forEach(key => delete props[key]); + menuInheritProps.forEach(key => delete props[key]); return (
  • triggerNode.parentNode; const popupPlacement = popupPlacementMap[props.mode]; const popupClassName = props.mode === 'inline' ? '' : props.popupClassName; - [ - 'parentMenu', - 'title', - 'selectedKeys', - 'openKeys', - 'onClick', - 'onOpenChange', - 'rootPrefixCls', - 'eventKey', - 'multiple', - 'active', - 'onItemHover', - 'onSelect', - 'triggerSubMenuAction', - 'onDeselect', - 'onDestroy', - 'onMouseEnter', - 'onMouseLeave', - 'onTitleMouseEnter', - 'onTitleMouseLeave', - 'onTitleClick', - 'isOpen', - ].forEach(key => delete props[key]); + menuInheritProps.forEach(key => delete props[key]); return (
  • {isInlineMode && title} diff --git a/src/SubPopupMenu.js b/src/SubPopupMenu.js index 4bab00ca..6457a6e6 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 } from './util'; +import { getKeyFromChildrenIndex, loopMenuItem, noop, menuInheritProps } from './util'; import DOMWrap from './DOMWrap'; function allDisabled(arr) { @@ -323,33 +323,7 @@ export class SubPopupMenu extends React.Component { domProps.tabIndex = '0'; domProps.onKeyDown = this.onKeyDown; } - [ - 'defaultSelectedKeys', - 'selectedKeys', - 'defaultOpenKeys', - 'openKeys', - 'mode', - 'getPopupContainer', - 'onClick', - 'onSelect', - 'onDeselect', - 'onDestroy', - 'openTransitionName', - 'openAnimation', - 'subMenuOpenDelay', - 'subMenuCloseDelay', - 'forceSubMenuRender', - 'triggerSubMenuAction', - 'level', - 'selectable', - 'multiple', - 'onOpenChange', - 'visible', - 'focusable', - 'defaultActiveFirst', - 'prefixCls', - 'inlineIndent', - ].forEach(key => delete props[key]); + menuInheritProps.forEach(key => delete props[key]); return ( // ESLint is not smart enough to know that the type of `children` was checked. /* eslint-disable */ diff --git a/src/util.js b/src/util.js index 82c07f4f..c0a49f79 100644 --- a/src/util.js +++ b/src/util.js @@ -36,8 +36,8 @@ export function loopMenuItemRecursively(children, keys, ret) { if (c) { const construct = c.type; if (!construct - || - !(construct.isSubMenu || construct.isMenuItem || construct.isMenuItemGroup) + || + !(construct.isSubMenu || construct.isMenuItem || construct.isMenuItemGroup) ) { return; } @@ -49,3 +49,49 @@ export function loopMenuItemRecursively(children, keys, ret) { } }); } + +export const menuInheritProps = [ + 'defaultSelectedKeys', + 'selectedKeys', + 'defaultOpenKeys', + 'openKeys', + 'mode', + 'getPopupContainer', + 'onClick', + 'onSelect', + 'onDeselect', + 'onDestroy', + 'openTransitionName', + 'openAnimation', + 'subMenuOpenDelay', + 'subMenuCloseDelay', + 'forceSubMenuRender', + 'triggerSubMenuAction', + 'level', + 'selectable', + 'multiple', + 'onOpenChange', + 'visible', + 'focusable', + 'defaultActiveFirst', + 'prefixCls', + 'inlineIndent', + 'parentMenu', + 'title', + 'rootPrefixCls', + 'eventKey', + 'active', + 'onItemHover', + 'onMouseEnter', + 'onMouseLeave', + 'onTitleMouseEnter', + 'onTitleMouseLeave', + 'onTitleClick', + 'isOpen', + 'renderMenuItem', + 'manualRef', + 'subMenuKey', + 'disabled', + 'index', + 'isSelected', +] \ No newline at end of file From a925c9c9a41b4684c076fcb5eab98c4629a51e91 Mon Sep 17 00:00:00 2001 From: jljsj33 Date: Fri, 20 Apr 2018 14:39:43 +0800 Subject: [PATCH 08/16] fix lint --- src/MenuItem.jsx | 2 +- src/util.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MenuItem.jsx b/src/MenuItem.jsx index 5ad2da35..4db82a98 100644 --- a/src/MenuItem.jsx +++ b/src/MenuItem.jsx @@ -161,7 +161,7 @@ export class MenuItem extends React.Component { onMouseEnter: this.onMouseEnter, }; } - menuInheritProps.forEach(key => delete props[key]) + menuInheritProps.forEach(key => delete props[key]); const style = { ...props.style, }; diff --git a/src/util.js b/src/util.js index c0a49f79..973e25e8 100644 --- a/src/util.js +++ b/src/util.js @@ -94,4 +94,4 @@ export const menuInheritProps = [ 'disabled', 'index', 'isSelected', -] \ No newline at end of file +]; From 5e68def722ebf736067543b19b52ea3d94a6fd69 Mon Sep 17 00:00:00 2001 From: jljsj33 Date: Fri, 20 Apr 2018 14:54:42 +0800 Subject: [PATCH 09/16] item props store --- src/util.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util.js b/src/util.js index 973e25e8..8eb71157 100644 --- a/src/util.js +++ b/src/util.js @@ -94,4 +94,5 @@ export const menuInheritProps = [ 'disabled', 'index', 'isSelected', + 'store', ]; From 28cb9c8fe489b436fa26cfb2e1890f40b2f79df1 Mon Sep 17 00:00:00 2001 From: jljsj33 Date: Fri, 20 Apr 2018 16:29:13 +0800 Subject: [PATCH 10/16] item props activeKey --- src/util.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util.js b/src/util.js index 8eb71157..e1b23375 100644 --- a/src/util.js +++ b/src/util.js @@ -95,4 +95,5 @@ export const menuInheritProps = [ 'index', 'isSelected', 'store', + 'activeKey', ]; From 2b5c70a186f426436369a2eed6708b135fd7adb8 Mon Sep 17 00:00:00 2001 From: jljsj33 Date: Fri, 20 Apr 2018 17:59:48 +0800 Subject: [PATCH 11/16] fix --- src/MenuItem.jsx | 2 +- src/MenuItemGroup.jsx | 5 +++-- src/SubMenu.jsx | 15 +++++++++++---- src/SubPopupMenu.js | 7 ++++--- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/MenuItem.jsx b/src/MenuItem.jsx index 4db82a98..68faf4f7 100644 --- a/src/MenuItem.jsx +++ b/src/MenuItem.jsx @@ -161,13 +161,13 @@ export class MenuItem extends React.Component { onMouseEnter: this.onMouseEnter, }; } - menuInheritProps.forEach(key => delete props[key]); const style = { ...props.style, }; if (props.mode === 'inline') { style.paddingLeft = props.inlineIndent * props.level; } + menuInheritProps.forEach(key => delete props[key]); return (
  • delete props[key]); return (
  • - {props.title} + {title}