Skip to content

Commit f8987e1

Browse files
committed
fix(CNavGroup): emit proper event when the visible property changed
1 parent e65fd55 commit f8987e1

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

packages/coreui-vue/src/components/nav/CNavGroup.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { watch } from '@vue/runtime-core'
2-
import { defineComponent, h, onMounted, onUpdated, ref, RendererElement, Transition } from 'vue'
1+
import { defineComponent, h, onMounted, ref, RendererElement, Transition, watch } from 'vue'
32

43
const CNavGroup = defineComponent({
54
name: 'CNavGroup',
@@ -19,7 +18,7 @@ const CNavGroup = defineComponent({
1918
},
2019
emits: ['visible-change'],
2120
setup(props, { slots, emit }) {
22-
const visible = ref(props.active || props.visible)
21+
const visible = ref()
2322
const navGroupRef = ref()
2423

2524
const visibleGroup = ref()
@@ -37,24 +36,29 @@ const CNavGroup = defineComponent({
3736
const isVisible = (index: number) => Boolean(visibleGroup.value === index)
3837

3938
onMounted(() => {
39+
visible.value = props.active || props.visible
4040
if (props.active || props.visible) navGroupRef.value.classList.add('show')
4141
emit('visible-change', visible.value)
4242
})
4343

44-
onUpdated(() => {
45-
visible.value = props.visible
44+
watch(
45+
() => props.visible,
46+
() => {
47+
visible.value = props.visible
4648

47-
if (visible.value === false) {
48-
visibleGroup.value = undefined
49-
}
50-
})
49+
if (visible.value === false) {
50+
visibleGroup.value = undefined
51+
}
52+
},
53+
)
5154

5255
watch(visible, () => {
5356
emit('visible-change', visible.value)
5457
})
5558

56-
const handleTogglerClick = function () {
59+
const handleTogglerClick = () => {
5760
visible.value = !visible.value
61+
emit('visible-change', visible.value)
5862
}
5963

6064
const handleBeforeEnter = (el: RendererElement) => {

0 commit comments

Comments
 (0)