fix(components): [menu] fix sliceIndex calculation error (#19164)

fix(components): [menu] Fix 'sliceIndex' calculation error

closed #19161
This commit is contained in:
wen_lun 2024-12-16 18:53:03 +08:00 committed by GitHub
parent 83cda2115a
commit 8b829ea7d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -326,10 +326,7 @@ export default defineComponent({
const calcSliceIndex = () => {
if (!menu.value) return -1
const items = Array.from(menu.value?.childNodes ?? []).filter(
(item) =>
// remove comment type node #12634
item.nodeName !== '#comment' &&
(item.nodeName !== '#text' || item.nodeValue)
(item) => item.nodeName !== '#text' || item.nodeValue
) as HTMLElement[]
const moreItemWidth = 64
const computedMenuStyle = getComputedStyle(menu.value!)
@ -339,6 +336,7 @@ export default defineComponent({
let calcWidth = 0
let sliceIndex = 0
items.forEach((item, index) => {
if (item.nodeName === '#comment') return
calcWidth += calcMenuItemWidth(item)
if (calcWidth <= menuWidth - moreItemWidth) {
sliceIndex = index + 1