-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
VueSelectButton.vue
52 lines (45 loc) · 1.12 KB
/
VueSelectButton.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<template>
<VueGroupButton
ref="groupButton"
v-close-popper="true"
class="vue-ui-select-button"
:label="label"
flat
@selected="onSelect"
>
<slot />
</VueGroupButton>
</template>
<script lang="ts">
import { defineComponent, inject, onMounted, getCurrentInstance, ComponentInternalInstance, Ref, ref } from 'vue'
export default defineComponent({
name: 'VueSelectButton',
props: {
label: {
type: String,
default: null,
},
},
setup () {
const currentInstance = getCurrentInstance()
const groupButton = ref(null)
const { setCurrentChild, getCurrentChild } = inject<{
setCurrentChild: (child: ComponentInternalInstance) => void
getCurrentChild: () => Ref<ComponentInternalInstance | null>}>('VueSelect')
onMounted(() => {
onSelect(groupButton.value.selected)
})
function onSelect (selected: boolean) {
if (selected) {
setCurrentChild(currentInstance)
} else if (getCurrentChild()?.value === currentInstance) {
setCurrentChild(null)
}
}
return {
groupButton,
onSelect,
}
},
})
</script>