Socket
Socket
Sign inDemoInstall

rc-menu

Package Overview
Dependencies
Maintainers
2
Versions
279
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.3.0 to 3.4.0

lib/MenuItemGroup.js

6

HISTORY.md
# History
----
## 3.4.0 / 2015-06-17
`improved` [#9](https://github.com/react-component/menu/issues/9) allow not set key for menuitem
`new`
## 3.3.0 / 2015-06-08

@@ -5,0 +11,0 @@

8

lib/Divider.js
'use strict';
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();

@@ -10,3 +12,2 @@

var React = require('react');
var assign = require('object-assign');

@@ -27,8 +28,7 @@ var Divider = (function (_React$Component) {

value: function render() {
var props = assign({}, this.props);
var props = this.props;
var className = props.className || '';
var rootPrefixCls = props.rootPrefixCls;
className += ' ' + ('' + rootPrefixCls + '-item-divider');
props.className = className;
return React.createElement('li', props);
return React.createElement('li', _extends({}, props, { className: className }));
}

@@ -35,0 +35,0 @@ }]);

@@ -6,3 +6,4 @@ 'use strict';

Menu.Item = require('./MenuItem');
Menu.ItemGroup = require('./MenuItemGroup');
Menu.Divider = require('./Divider');
module.exports = Menu;

@@ -23,10 +23,21 @@ 'use strict';

var now = Date.now();
function getChildIndexInChildren(child, children) {
var index = -1;
React.Children.forEach(children, function (c, i) {
if (c === child) {
index = i;
}
});
return index;
}
function getKeyFromChildren(child, children) {
return child.key || 'rcMenuItem_' + now + '_' + getChildIndexInChildren(child, children);
}
function getActiveKey(props) {
var activeKey = props.activeKey;
var children = props.children;
React.Children.forEach(children, function (c) {
if (!c.key && !c.props.disabled) {
throw new Error('MenuItem must have key!');
}
});
if (activeKey) {

@@ -37,3 +48,3 @@ return activeKey;

if (c.props.active) {
activeKey = c.key;
activeKey = getKeyFromChildren(c, children);
}

@@ -44,3 +55,3 @@ });

if (!activeKey && !c.props.disabled) {
activeKey = c.key;
activeKey = getKeyFromChildren(c, children);
}

@@ -54,4 +65,5 @@ });

function saveRef(name, c) {
this.instances = this.instances || {};
this.instances[name] = c;
if (c) {
this.instanceArray.push(c);
}
}

@@ -71,3 +83,3 @@

['handleItemHover', 'handleDeselect', 'handleSelect', 'handleKeyDown', 'handleDestroy'].forEach(function (m) {
['handleItemHover', 'handleDeselect', 'handleSelect', 'handleKeyDown', 'handleDestroy', 'renderMenuItem'].forEach(function (m) {
_this[m] = _this[m].bind(_this);

@@ -91,13 +103,2 @@ });

}, {
key: 'getChildrenComponents',
value: function getChildrenComponents() {
var _this2 = this;
var ret = [];
this.newChildren.forEach(function (c) {
ret.push(_this2.instances[c.key]);
});
return ret;
}
}, {
key: 'handleKeyDown',

@@ -107,9 +108,8 @@

value: function handleKeyDown(e) {
var _this3 = this;
var _this2 = this;
var keyCode = e.keyCode;
var handled;
this.newChildren.forEach(function (c) {
var obj = _this3.instances[c.key];
if (c.props.active) {
this.instanceArray.forEach(function (obj) {
if (obj.props.active) {
handled = obj.handleKeyDown(e);

@@ -119,26 +119,26 @@ }

if (handled) {
return true;
return 1;
}
var activeKey;
var activeItem;
switch (keyCode) {
case KeyCode.UP:
//up
activeKey = this.step(-1);
activeItem = this.step(-1);
break;
case KeyCode.DOWN:
//down
activeKey = this.step(1);
activeItem = this.step(1);
break;
default:
}
if (activeKey) {
if (activeItem) {
e.preventDefault();
this.setState({
activeKey: activeKey
activeKey: activeItem.props.eventKey
}, function () {
scrollIntoView(React.findDOMNode(_this3.instances[activeKey]), React.findDOMNode(_this3), {
scrollIntoView(React.findDOMNode(activeItem), React.findDOMNode(_this2), {
onlyScrollIfNeeded: true
});
});
return true;
return 1;
}

@@ -149,3 +149,3 @@ }

value: function step(direction) {
var children = this.newChildren;
var children = this.instanceArray;
var activeKey = this.state.activeKey;

@@ -159,3 +159,3 @@ var len = children.length;

children.every(function (c, ci) {
if (c.key === activeKey) {
if (c.props.eventKey === activeKey) {
activeIndex = ci;

@@ -170,3 +170,2 @@ return false;

var child = children[i];
var key = child.key;
if (child.props.disabled) {

@@ -179,3 +178,3 @@ i = (i + 1 + len) % len;

} else {
return key;
return child;
}

@@ -212,3 +211,3 @@ }

// my child
if (this.getChildrenComponents().indexOf(child) !== -1) {
if (this.instanceArray.indexOf(child) !== -1) {
var selectedKeys;

@@ -233,3 +232,3 @@ if (props.multiple) {

var state = this.state;
var children = this.getChildrenComponents();
var children = this.instanceArray;
// my children

@@ -266,7 +265,8 @@ if (children.indexOf(child) !== -1 && children.indexOf(__childToBeSelected) === -1) {

value: function renderMenuItem(child) {
var key = child.key;
var state = this.state;
var props = this.props;
var key = getKeyFromChildren(child, props.children);
var childProps = child.props;
return React.cloneElement(child, {
renderMenuItem: this.renderMenuItem,
rootPrefixCls: props.prefixCls,

@@ -276,6 +276,6 @@ ref: createChainedFunction(child.ref, saveRef.bind(this, key)),

onHover: this.handleItemHover,
active: key === state.activeKey,
active: !childProps.disabled && key === state.activeKey,
multiple: props.multiple,
selected: state.selectedKeys.indexOf(key) !== -1,
onClick: this.props.onClick,
onClick: props.onClick,
onDeselect: createChainedFunction(childProps.onDeselect, this.handleDeselect),

@@ -290,2 +290,3 @@ onDestroy: this.handleDestroy,

var props = this.props;
this.instanceArray = [];
var classes = {};

@@ -305,4 +306,2 @@ classes[props.prefixCls] = true;

}
this.newChildren = rcUtil.Children.toArray(props.children).map(this.renderMenuItem, this);
return React.createElement(

@@ -313,3 +312,3 @@ 'ul',

}, domProps),
this.newChildren
React.Children.map(props.children, this.renderMenuItem)
);

@@ -316,0 +315,0 @@ }

{
"name": "rc-menu",
"version": "3.3.0",
"version": "3.4.0",
"description": "menu ui component for react",

@@ -55,3 +55,2 @@ "keywords": [

"dom-scroll-into-view": "^1.0.1",
"object-assign": "~3.0.0",
"rc-util": "2.x"

@@ -58,0 +57,0 @@ },

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc