fix(Tabs): incorrect insert position in some cases (#11462)

This commit is contained in:
neverland
2023-01-07 16:59:52 +08:00
committed by GitHub
parent 609ec4579b
commit 307b586d49
3 changed files with 103 additions and 2 deletions

View File

@@ -37,6 +37,20 @@ export function flattenVNodes(children: VNodeNormalizedChildren) {
return result;
}
const findVNodeIndex = (vnodes: VNode[], vnode: VNode) => {
const index = vnodes.indexOf(vnode);
if (index === -1) {
return vnodes.findIndex(
(item) =>
vnode.key !== undefined &&
vnode.key !== null &&
item.type === vnode.type &&
item.key === vnode.key
);
}
return index;
};
// sort children instances by vnodes order
export function sortChildren(
parent: ComponentInternalInstance,
@@ -46,7 +60,7 @@ export function sortChildren(
const vnodes = flattenVNodes(parent.subTree.children);
internalChildren.sort(
(a, b) => vnodes.indexOf(a.vnode) - vnodes.indexOf(b.vnode)
(a, b) => findVNodeIndex(vnodes, a.vnode) - findVNodeIndex(vnodes, b.vnode)
);
const orderedPublicChildren = internalChildren.map((item) => item.proxy!);