|
1 | 1 | <script setup lang="ts"> |
2 | 2 | import ClickOutside from '@/services/ClickOutside'; |
3 | 3 | import {setRelativeTo} from '@/services/Positioner'; |
4 | | -import {onUpdated, ref, watch} from 'vue'; |
| 4 | +import {onMounted, onUpdated, ref, watch} from 'vue'; |
5 | 5 |
|
6 | 6 | const active = ref<boolean>(false); |
7 | 7 | const dropdownRef = ref(); |
8 | 8 | const clickOutside = new ClickOutside([], () => toggle(false)); |
9 | | -const props = defineProps<{ alignment: 'left' | 'right', split: boolean }>(); |
| 9 | +const props = defineProps<{ alignment: 'left' | 'right', split: boolean, hideOnSelected?: boolean }>(); |
10 | 10 |
|
11 | 11 | const toggle = (forceActive: boolean | null = null): void => { |
12 | | - active.value = forceActive ?? !active.value; |
| 12 | + active.value = forceActive ?? !active.value; |
13 | 13 | } |
14 | 14 |
|
15 | 15 | watch(active, () => setTimeout(() => clickOutside.enable(active.value), 1)); |
16 | 16 |
|
| 17 | +onMounted(() => { |
| 18 | + if (props.hideOnSelected !== true) { |
| 19 | + clickOutside.addElement(dropdownRef.value); |
| 20 | + } |
| 21 | +}) |
17 | 22 | onUpdated(() => { |
18 | | - if (active.value === false) { |
19 | | - return; |
20 | | - } |
21 | | - setRelativeTo(dropdownRef.value.parentElement, dropdownRef.value, props.alignment); |
| 23 | + if (active.value === false) { |
| 24 | + return; |
| 25 | + } |
| 26 | + setRelativeTo(dropdownRef.value.parentElement, dropdownRef.value, props.alignment); |
22 | 27 | }); |
23 | 28 | defineExpose({toggle}); |
24 | 29 | </script> |
25 | 30 |
|
26 | 31 | <template> |
27 | | - <div class="slv-btn-group" :class="{ 'btn-group': split, 'dropdown': !split }"> |
28 | | - <slot name="btn_left"></slot> |
29 | | - <slot name="btn_right"></slot> |
30 | | - <ul class="dropdown-menu" :class="{'d-block': active}" ref="dropdownRef"> |
31 | | - <slot name="dropdown"></slot> |
32 | | - </ul> |
33 | | - </div> |
| 32 | + <div class="slv-btn-group" :class="{ 'btn-group': split, 'dropdown': !split }"> |
| 33 | + <slot name="btn_left"></slot> |
| 34 | + <slot name="btn_right"></slot> |
| 35 | + <ul class="dropdown-menu" :class="{'d-block': active}" ref="dropdownRef"> |
| 36 | + <slot name="dropdown"></slot> |
| 37 | + </ul> |
| 38 | + </div> |
34 | 39 | </template> |
0 commit comments