Skip to content

Commit f06d191

Browse files
Allow using v-model on accordion activeItemKey
I needed a reactive way to change the currently open accordion item, and this seems to do the trick.
1 parent a9fca48 commit f06d191

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/coreui-vue/src/components/accordion/CAccordion.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineComponent, h, provide, ref } from 'vue'
1+
import { defineComponent, h, provide, ref, watch } from 'vue'
22

33
const CAccordion = defineComponent({
44
name: 'CAccordion',
@@ -16,14 +16,19 @@ const CAccordion = defineComponent({
1616
*/
1717
flush: Boolean,
1818
},
19+
emits: ['update:activeItemKey'],
1920
setup(props, { slots }) {
2021
const activeItemKey = ref(props.activeItemKey)
2122
const setActiveItemKey = (key: string | number) => {
22-
activeItemKey.value = key
23+
emit('update:activeItemKey', key)
2324
}
2425
provide('activeItemKey', activeItemKey)
2526
provide('alwaysOpen', props.alwaysOpen)
2627
provide('setActiveItemKey', setActiveItemKey)
28+
29+
watch(() => props.activeItemKey, (value) => {
30+
activeItemKey.value = value;
31+
})
2732

2833
return () =>
2934
h(

0 commit comments

Comments
 (0)