2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2024-02-11 08:10:29 +00:00
|
|
|
<div :class="containerClass" :style="style" v-bind="ptmi('root')" :data-p-severity="severity">
|
2024-02-03 08:49:13 +00:00
|
|
|
<PVSButton
|
|
|
|
type="button"
|
2024-05-06 15:23:01 +00:00
|
|
|
:class="cx('pcButton')"
|
2024-02-03 08:49:13 +00:00
|
|
|
:label="label"
|
|
|
|
:disabled="disabled"
|
|
|
|
:severity="severity"
|
|
|
|
:text="text"
|
|
|
|
:outlined="outlined"
|
|
|
|
:size="size"
|
|
|
|
:aria-label="label"
|
|
|
|
@click="onDefaultButtonClick"
|
|
|
|
v-bind="buttonProps"
|
2024-05-06 15:23:01 +00:00
|
|
|
:pt="ptm('pcButton')"
|
2024-02-03 08:49:13 +00:00
|
|
|
:unstyled="unstyled"
|
|
|
|
>
|
|
|
|
<template v-if="$slots.icon" #icon="slotProps">
|
|
|
|
<slot name="icon" :class="slotProps.class">
|
2024-05-06 15:23:01 +00:00
|
|
|
<span :class="[icon, slotProps.class]" v-bind="ptm('pcButton')['icon']" data-pc-section="buttonicon" />
|
2024-02-03 08:49:13 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
|
|
|
<template #default>
|
|
|
|
<slot></slot>
|
|
|
|
</template>
|
|
|
|
</PVSButton>
|
2022-12-08 11:04:25 +00:00
|
|
|
<PVSButton
|
|
|
|
ref="button"
|
|
|
|
type="button"
|
2024-05-06 15:23:01 +00:00
|
|
|
:class="cx('pcDropdown')"
|
2022-12-08 11:04:25 +00:00
|
|
|
:disabled="disabled"
|
|
|
|
aria-haspopup="true"
|
|
|
|
:aria-expanded="isExpanded"
|
2024-02-02 15:47:58 +00:00
|
|
|
:aria-controls="id + '_overlay'"
|
2022-12-08 11:04:25 +00:00
|
|
|
@click="onDropdownButtonClick"
|
|
|
|
@keydown="onDropdownKeydown"
|
2023-08-04 11:04:39 +00:00
|
|
|
:severity="severity"
|
|
|
|
:text="text"
|
|
|
|
:outlined="outlined"
|
|
|
|
:size="size"
|
2023-06-12 07:11:42 +00:00
|
|
|
:unstyled="unstyled"
|
2024-04-30 08:02:09 +00:00
|
|
|
v-bind="menuButtonProps"
|
2024-05-06 15:23:01 +00:00
|
|
|
:pt="ptm('pcDropdown')"
|
2023-04-10 11:57:23 +00:00
|
|
|
>
|
2023-04-19 07:50:39 +00:00
|
|
|
<template #icon="slotProps">
|
2024-05-02 10:50:07 +00:00
|
|
|
<!--TODO: menubuttonicon and menuButtonIcon deprecated since v4.0-->
|
|
|
|
<slot :name="$slots.dropdownicon ? 'dropdownicon' : 'menubuttonicon'" :class="slotProps.class">
|
2024-05-06 15:23:01 +00:00
|
|
|
<component :is="menuButtonIcon || dropdownIcon ? 'span' : 'ChevronDownIcon'" :class="[dropdownIcon || menuButtonIcon, slotProps.class]" v-bind="ptm('pcDropdown')['icon']" data-pc-section="menubuttonicon" />
|
2023-04-14 07:44:20 +00:00
|
|
|
</slot>
|
|
|
|
</template>
|
2023-04-10 11:57:23 +00:00
|
|
|
</PVSButton>
|
2024-05-06 15:23:01 +00:00
|
|
|
<PVSMenu ref="menu" :id="id + '_overlay'" :model="model" :popup="true" :autoZIndex="autoZIndex" :baseZIndex="baseZIndex" :appendTo="appendTo" :unstyled="unstyled" :pt="ptm('ptMenu')">
|
2023-08-28 13:29:49 +00:00
|
|
|
<template v-if="$slots.menuitemicon" #itemicon="slotProps">
|
2023-08-31 15:31:18 +00:00
|
|
|
<slot name="menuitemicon" :item="slotProps.item" :class="slotProps.class" />
|
2023-08-28 13:29:49 +00:00
|
|
|
</template>
|
2023-10-31 13:38:09 +00:00
|
|
|
<template v-if="$slots.item" #item="slotProps">
|
|
|
|
<slot name="item" :item="slotProps.item" :hasSubmenu="slotProps.hasSubmenu" :label="slotProps.label" :props="slotProps.props"></slot>
|
|
|
|
</template>
|
2023-08-28 13:29:49 +00:00
|
|
|
</PVSMenu>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import Button from 'primevue/button';
|
2023-04-18 12:53:43 +00:00
|
|
|
import ChevronDownIcon from 'primevue/icons/chevrondown';
|
2022-09-06 12:03:37 +00:00
|
|
|
import TieredMenu from 'primevue/tieredmenu';
|
2022-09-14 11:26:01 +00:00
|
|
|
import { UniqueComponentId } from 'primevue/utils';
|
2023-05-30 14:17:32 +00:00
|
|
|
import BaseSplitButton from './BaseSplitButton.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'SplitButton',
|
2023-05-30 14:17:32 +00:00
|
|
|
extends: BaseSplitButton,
|
2024-02-11 08:10:29 +00:00
|
|
|
inheritAttrs: false,
|
2022-12-31 09:51:37 +00:00
|
|
|
emits: ['click'],
|
2022-12-08 11:04:25 +00:00
|
|
|
data() {
|
|
|
|
return {
|
2024-02-02 15:47:58 +00:00
|
|
|
id: this.$attrs.id,
|
2022-12-08 11:04:25 +00:00
|
|
|
isExpanded: false
|
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2024-02-02 15:47:58 +00:00
|
|
|
watch: {
|
2024-04-16 09:35:02 +00:00
|
|
|
'$attrs.id': function (newValue) {
|
|
|
|
this.id = newValue || UniqueComponentId();
|
2024-03-27 23:27:46 +00:00
|
|
|
}
|
2024-02-02 15:47:58 +00:00
|
|
|
},
|
2023-06-20 07:29:55 +00:00
|
|
|
mounted() {
|
2024-04-16 09:35:02 +00:00
|
|
|
this.id = this.id || UniqueComponentId();
|
|
|
|
|
2023-06-20 07:29:55 +00:00
|
|
|
this.$watch('$refs.menu.visible', (newValue) => {
|
|
|
|
this.isExpanded = newValue;
|
|
|
|
});
|
|
|
|
},
|
2022-09-06 12:03:37 +00:00
|
|
|
methods: {
|
2023-07-31 12:54:09 +00:00
|
|
|
onDropdownButtonClick(event) {
|
2023-10-12 01:33:01 +00:00
|
|
|
if (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
2022-12-08 11:04:25 +00:00
|
|
|
this.$refs.menu.toggle({ currentTarget: this.$el, relatedTarget: this.$refs.button.$el });
|
2023-06-20 07:29:55 +00:00
|
|
|
this.isExpanded = this.$refs.menu.visible;
|
2022-12-08 11:04:25 +00:00
|
|
|
},
|
|
|
|
onDropdownKeydown(event) {
|
|
|
|
if (event.code === 'ArrowDown' || event.code === 'ArrowUp') {
|
|
|
|
this.onDropdownButtonClick();
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2022-09-06 12:03:37 +00:00
|
|
|
},
|
2022-12-08 11:04:25 +00:00
|
|
|
onDefaultButtonClick(event) {
|
2023-03-17 06:59:23 +00:00
|
|
|
if (this.isExpanded) {
|
|
|
|
this.$refs.menu.hide(event);
|
|
|
|
}
|
2022-12-31 09:51:37 +00:00
|
|
|
|
2023-03-17 06:59:23 +00:00
|
|
|
this.$emit('click', event);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
containerClass() {
|
2023-05-30 14:17:32 +00:00
|
|
|
return [this.cx('root'), this.class];
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
2022-09-14 11:26:01 +00:00
|
|
|
PVSButton: Button,
|
2023-04-10 11:57:23 +00:00
|
|
|
PVSMenu: TieredMenu,
|
|
|
|
ChevronDownIcon: ChevronDownIcon
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2022-09-14 11:26:01 +00:00
|
|
|
};
|
2022-09-06 12:03:37 +00:00
|
|
|
</script>
|