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[]>([]) const buttonRefs = ref<Function[]>([])
function closeOthers (itemIndex: number) { function closeOthers (currentIndex: number) {
if (!props.items[itemIndex].closeOthers && props.multiple) { if (!props.items[currentIndex].closeOthers && props.multiple) {
return return
} }
buttonRefs.value.forEach((close, index) => { const totalItems = buttonRefs.value.length
if (index === itemIndex) return
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() close()
}) }
} }
function onEnter (el: HTMLElement, done) { function onEnter (el: HTMLElement, done) {