mirror of
https://github.com/youzan/vant.git
synced 2025-10-17 16:44:21 +00:00
fix(Tabs): incorrect insert position in some cases (#11462)
This commit is contained in:
@@ -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!);
|
||||
|
Reference in New Issue
Block a user