fix(Accordion): close other items in circular order (#735)

This commit is contained in:
Haytham A. Salama
2023-09-24 12:36:35 +03:00
committed by GitHub
parent d088d8a7b8
commit 6887f732ee

View File

@@ -100,16 +100,21 @@ export default defineComponent({
const buttonRefs = ref<Function[]>([])
function closeOthers (itemIndex: number) {
if (!props.items[itemIndex].closeOthers && props.multiple) {
function closeOthers (currentIndex: number) {
if (!props.items[currentIndex].closeOthers && props.multiple) {
return
}
buttonRefs.value.forEach((close, index) => {
if (index === itemIndex) return
const totalItems = buttonRefs.value.length
const order = Array.from({ length: totalItems }, (_, i) => (currentIndex + i) % totalItems)
.filter(index => index !== currentIndex)
.reverse()
for (const index of order) {
const close = buttonRefs.value[index]
close()
})
}
}
function onEnter (el: HTMLElement, done) {