-
-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: improve coverage and one minor bug fix #132
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,22 +175,8 @@ const Menu = createReactClass({ | |
return transitionName; | ||
}, | ||
|
||
isInlineMode() { | ||
return this.props.mode === 'inline'; | ||
}, | ||
|
||
lastOpenSubMenu() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not used anywhere |
||
let lastOpen = []; | ||
const { openKeys } = this.store.getState(); | ||
if (openKeys.length) { | ||
lastOpen = this.getFlatInstanceArray().filter((c) => { | ||
return c && openKeys.indexOf(c.props.eventKey) !== -1; | ||
}); | ||
} | ||
return lastOpen[0]; | ||
}, | ||
|
||
renderMenuItem(c, i, subIndex, subMenuKey) { | ||
renderMenuItem(c, i, subMenuKey) { | ||
/* istanbul ignore if */ | ||
if (!c) { | ||
return null; | ||
} | ||
|
@@ -201,7 +187,7 @@ const Menu = createReactClass({ | |
triggerSubMenuAction: this.props.triggerSubMenuAction, | ||
subMenuKey, | ||
}; | ||
return this.renderCommonMenuItem(c, i, subIndex, extraProps); | ||
return this.renderCommonMenuItem(c, i, extraProps); | ||
}, | ||
|
||
render() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ import { noop } from './util'; | |
|
||
/* eslint react/no-is-mounted:0 */ | ||
|
||
const MenuItem = createReactClass({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exporting only for test |
||
export const MenuItem = createReactClass({ | ||
displayName: 'MenuItem', | ||
|
||
propTypes: { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,14 +49,9 @@ export function getActiveKey(props, originalActiveKey) { | |
return activeKey; | ||
} | ||
|
||
function saveRef(index, subIndex, c) { | ||
function saveRef(index, c) { | ||
if (c) { | ||
if (subIndex !== undefined) { | ||
this.instanceArray[index] = this.instanceArray[index] || []; | ||
this.instanceArray[index][subIndex] = c; | ||
} else { | ||
this.instanceArray[index] = c; | ||
} | ||
this.instanceArray[index] = c; | ||
} | ||
} | ||
|
||
|
@@ -106,6 +101,7 @@ const MenuMixin = { | |
}, | ||
|
||
// all keyboard events callbacks run from here at first | ||
// FIXME: callback is currently used by rc-select, should be more explicit | ||
onKeyDown(e, callback) { | ||
const keyCode = e.keyCode; | ||
let handled; | ||
|
@@ -129,10 +125,6 @@ const MenuMixin = { | |
callback(activeItem); | ||
} | ||
|
||
return 1; | ||
} else if (activeItem === undefined) { | ||
e.preventDefault(); | ||
updateActiveKey(this.getStore(), this.getEventKey(), null); | ||
return 1; | ||
} | ||
}, | ||
|
@@ -154,25 +146,10 @@ const MenuMixin = { | |
}, | ||
|
||
getFlatInstanceArray() { | ||
let instanceArray = this.instanceArray; | ||
const hasInnerArray = instanceArray.some((a) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since subIndex is always invalid, hasInnerArray will never be true. |
||
return Array.isArray(a); | ||
}); | ||
if (hasInnerArray) { | ||
instanceArray = []; | ||
this.instanceArray.forEach((a) => { | ||
if (Array.isArray(a)) { | ||
instanceArray.push.apply(instanceArray, a); | ||
} else { | ||
instanceArray.push(a); | ||
} | ||
}); | ||
this.instanceArray = instanceArray; | ||
} | ||
return instanceArray; | ||
return this.instanceArray; | ||
}, | ||
|
||
renderCommonMenuItem(child, i, subIndex, extraProps) { | ||
renderCommonMenuItem(child, i, extraProps) { | ||
const state = this.getStore().getState(); | ||
const props = this.props; | ||
const key = getKeyFromChildrenIndex(child, props.eventKey, i); | ||
|
@@ -188,7 +165,7 @@ const MenuMixin = { | |
parentMenu: this, | ||
// customized ref function, need to be invoked manually in child's componentDidMount | ||
manualRef: childProps.disabled ? undefined : | ||
createChainedFunction(child.ref, saveRef.bind(this, i, subIndex)), | ||
createChainedFunction(child.ref, saveRef.bind(this, i)), | ||
eventKey: key, | ||
active: !childProps.disabled && isActive, | ||
multiple: props.multiple, | ||
|
@@ -241,7 +218,7 @@ const MenuMixin = { | |
> | ||
{React.Children.map( | ||
props.children, | ||
(c, i, subIndex) => this.renderMenuItem(c, i, subIndex, props.eventKey || '0-menu-'), | ||
(c, i) => this.renderMenuItem(c, i, props.eventKey || '0-menu-'), | ||
)} | ||
</DOMWrap> | ||
/*eslint-enable */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used anywhere