-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
fix menu mutli active item #1438
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 |
---|---|---|
|
@@ -21,56 +21,80 @@ export default class Menu extends React.Component<MenuProps, any> { | |
super(props); | ||
this.state = { | ||
firstLevelSelectValue: this.getNewFsv(props), | ||
value: props.value, | ||
}; | ||
} | ||
componentWillReceiveProps(nextProps) { | ||
if (nextProps.value !== this.props.value) { | ||
this.setState({ | ||
firstLevelSelectValue: this.getNewFsv(nextProps), | ||
value: nextProps.value, | ||
}); | ||
} | ||
} | ||
|
||
getNewFsv(props) { | ||
const { value, data } = props; | ||
return value && value.length ? value[0] : !data[0].isLeaf ? data[0].value : ''; | ||
let firstValue = ''; | ||
if (value && value.length) { // if has init path, chose init first value | ||
firstValue = value[0]; | ||
} else if (!data[0].isLeaf) { // chose the first menu item if it's not leaf. | ||
firstValue = data[0].value; | ||
} | ||
|
||
return firstValue; | ||
} | ||
|
||
onClickFirstLevelItem = (dataItem) => { | ||
const { onChange } = this.props; | ||
this.setState({ | ||
firstLevelSelectValue: dataItem.value, | ||
}); | ||
if (dataItem.isLeaf && this.props.onChange) { | ||
this.props.onChange([dataItem.value]); | ||
if (dataItem.isLeaf && onChange) { | ||
onChange([dataItem.value]); | ||
} | ||
} | ||
|
||
onClickSubMenuItem = (dataItem) => { | ||
const { level, onChange } = this.props; | ||
const value = (level === 2) ? [this.state.firstLevelSelectValue, dataItem.value] : [dataItem.value]; | ||
this.setState({ value }); | ||
setTimeout(() => { | ||
if (onChange) { | ||
onChange(level === 2 ? [this.state.firstLevelSelectValue, dataItem.value] : [dataItem.value]); | ||
onChange(value); | ||
} | ||
}, 300); | ||
} | ||
|
||
render() { | ||
const { className, style, height, data = [], prefixCls, value, level } = this.props; | ||
const { firstLevelSelectValue } = this.state; | ||
const { className, style, height, data = [], prefixCls, level } = this.props; | ||
const { firstLevelSelectValue, value } = this.state; | ||
let subMenuData = data; // menu only has one level as init | ||
|
||
if (level === 2) { | ||
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. 重新梳理了一下逻辑,加入了isLeaf === true 就不显示children 的判断 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. isLeaf的使用场景是干啥?demo里的isLeaf用来显示全部类型?也不太对啊 要问下这个组件最初的开发者 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. 这个跟@pingan1927 沟通过。 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. 👍 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. 文档和 demo 有可以完善的地方就直接改掉 |
||
let parent = data; | ||
if (firstLevelSelectValue && firstLevelSelectValue !== '') { | ||
parent = data.filter(dataItem => dataItem.value === firstLevelSelectValue); | ||
} | ||
|
||
let subMenuData = data[0].children || []; | ||
if (level !== 2) { | ||
subMenuData = data; | ||
} else if (firstLevelSelectValue) { | ||
subMenuData = data.filter(dataItem => dataItem.value === firstLevelSelectValue)[0].children || []; | ||
if (parent[0] && parent[0].children && parent[0].isLeaf !== true ) { | ||
subMenuData = parent[0].children; | ||
} else { | ||
subMenuData = []; | ||
} | ||
} | ||
|
||
const subValue = value && value.length && value[value.length - 1]; | ||
const subValue = value && (value.length > 0) && value[value.length - 1]; | ||
const parentValue = (value && (value.length > 1)) ? value[0] : null; | ||
const subSelInitItem = subMenuData.filter(dataItem => dataItem.value === subValue); | ||
|
||
let showSelect = true; | ||
if (level === 2 && parentValue !== firstLevelSelectValue) { | ||
showSelect = false; | ||
} | ||
|
||
const heightStyle = { | ||
height: `${Math.round(height || document.documentElement.clientHeight / 2)}px`, | ||
overflowY: 'scroll', | ||
}; | ||
|
||
return ( | ||
|
@@ -106,6 +130,7 @@ export default class Menu extends React.Component<MenuProps, any> { | |
subMenuData={subMenuData} | ||
selItem={subSelInitItem} | ||
onSel={this.onClickSubMenuItem} | ||
showSelect={showSelect} | ||
/> | ||
</Flex.Item> | ||
</Flex> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
.@{flexPrefixCls}-item { | ||
margin-left: 0; | ||
-webkit-overflow-scrolling: touch; | ||
overflow-y: scroll; | ||
|
||
.@{listPrefixCls} { | ||
padding: 0; | ||
|
@@ -97,6 +98,10 @@ | |
&:only-child { | ||
.@{listPrefixCls} { | ||
.@{listPrefixCls}-item { | ||
.@{listPrefixCls}-line { | ||
.hairline-bottom(@border-color-base); | ||
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. 单级情况下,每个ListItem的下边框缺失 |
||
} | ||
|
||
&:last-child { | ||
.hairline-bottom(@border-color-base); | ||
|
||
|
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.
getNewFsv
的写法也改写下吧,这个写法很难阅读。