Last active
January 25, 2022 09:00
-
-
Save sadewole/d975992ddfcc8e8cc9981b084da0493c to your computer and use it in GitHub Desktop.
AccordionItem.vue - Script: getExpandCondition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script lang="ts"> | |
... // content hidden | |
export default defineComponent({ | |
name: "AccordionItem", | |
... // content hidden | |
setup(props: Props) { | |
const id = ref(useId()); | |
const isExpanded = ref(props.defaultIsOpen || false); | |
const allowMultiple = inject("allowMultiple") as boolean; | |
const indices = inject("indices") as Indices; | |
const expandedIndex = inject("expandedIndex") as ExpandedIndex; | |
... // content hidden | |
const getExpandCondition = ( | |
arrIndex: string | Array<string>, | |
itemIndex: string | |
) => { | |
if (Array.isArray(arrIndex)) { | |
return arrIndex.includes(itemIndex); | |
} | |
return arrIndex === itemIndex; | |
}; | |
watch( | |
() => expandedIndex.value, | |
() => { | |
isExpanded.value = getExpandCondition(expandedIndex.value, id.value); | |
} | |
); | |
onMounted(watchExpand); | |
onUpdated(watchExpand); | |
return { isExpanded, toggleContent }; | |
}, | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment