-
Notifications
You must be signed in to change notification settings - Fork 358
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): fix submenu parent item active status on mounted #3357
Open
uyarn
wants to merge
3
commits into
develop
Choose a base branch
from
fix/submenu-highlight
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ import { | |
reactive, | ||
} from '@vue/composition-api'; | ||
import isFunction from 'lodash/isFunction'; | ||
import get from 'lodash/get'; | ||
import props from './submenu-props'; | ||
import { renderContent, renderTNodeJSX } from '../utils/render-tnode'; | ||
import FakeArrow from '../common-components/fake-arrow'; | ||
|
@@ -27,9 +28,10 @@ import { TdSubmenuProps } from './type'; | |
import useCollapseAnimation from '../hooks/useCollapseAnimation'; | ||
|
||
const keepAnimationMixins = getKeepAnimationMixins(); | ||
const submenuName = 'TSubmenu'; | ||
|
||
export default defineComponent({ | ||
name: 'TSubmenu', | ||
name: submenuName, | ||
components: { | ||
FakeArrow, | ||
}, | ||
|
@@ -38,7 +40,7 @@ export default defineComponent({ | |
ripple: Ripple, | ||
}, | ||
props, | ||
setup(props) { | ||
setup(props, { slots }) { | ||
const menu = inject<TdMenuInterface>('TdMenu'); | ||
const { | ||
theme, activeValues, expandValues, mode, isHead, open, | ||
|
@@ -216,10 +218,52 @@ export default defineComponent({ | |
while (node && !/^t(head)?menu/i.test(node.vnode?.tag)) { | ||
if (/submenu/i.test(node.vnode?.tag)) { | ||
isNested.value = true; | ||
|
||
break; | ||
} | ||
node = node?.parent; | ||
} | ||
const activeValue = menu?.activeValue.value; | ||
if (activeValue !== props.value && mode.value === 'popup') { | ||
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. 这里的代码板块理解过于复杂,建议定义单独的函数分别计算 |
||
const childNode = slots.default?.() || []; | ||
// 递归获取子菜单 处理折叠场景初始化时子菜单item未渲染,没有加入 vMenu,导致没有正常高亮父节点的展示问题 | ||
for (let i = 0; i < childNode.length; i++) { | ||
const item = childNode[i]; | ||
// 菜单最多支持三级,所以可能有两层子菜单嵌套 | ||
if (get(item, 'componentOptions.Ctor.extendOptions.name') === submenuName) { | ||
const submenu = item; | ||
const subChildNode = submenu.componentOptions.children || []; | ||
for (let j = 0; j < subChildNode.length; j++) { | ||
const subMenuChildItem = subChildNode[j]; | ||
const subMenuValue = (submenu.componentOptions.propsData as TdSubmenuProps)?.value; | ||
const menuItemValue = (subMenuChildItem.componentOptions.propsData as TdSubmenuProps)?.value; | ||
|
||
if (menuItemValue === activeValue) { | ||
// 需要将子菜单及其二级节点都接入 vMenu | ||
menu?.vMenu?.add({ | ||
value: subMenuValue, | ||
parent: props.value, | ||
}); | ||
menu?.vMenu?.add({ | ||
value: menuItemValue, | ||
parent: subMenuValue, | ||
}); | ||
// 找到需要高亮的子菜单即退出循环 | ||
break; | ||
} | ||
} | ||
} | ||
const menuItemValue = (item.componentOptions.propsData as TdSubmenuProps)?.value; | ||
if (menuItemValue === activeValue) { | ||
menu?.vMenu?.add({ | ||
value: menuItemValue, | ||
parent: props.value, | ||
}); | ||
// 找到需要高亮的子菜单即退出循环 | ||
break; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
return { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
这里的名字改的我有点慌,曾经这里也写的是变量,但是打包后,失效了
然后有一次,就全部重新改成字符串了
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.
这个地方还是字符串没变 是方便后面取该组件使用