primevue-mirror/components/lib/splitbutton/SplitButton.vue

95 lines
3.3 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2023-05-30 14:17:32 +00:00
<div :class="containerClass" :style="style" v-bind="ptm('root')" data-pc-name="splitbutton" :data-pc-severity="severity">
2022-09-06 12:03:37 +00:00
<slot>
<PVSButton type="button" :class="cx('button')" :label="label" :disabled="disabled" :aria-label="label" @click="onDefaultButtonClick" :pt="ptm('button')" v-bind="buttonProps" :unstyled="unstyled" data-pc-section="button">
<template v-if="icon" #icon="slotProps">
2023-06-06 08:14:14 +00:00
<slot name="icon" :class="slotProps.class">
<span :class="[icon, slotProps.class]" v-bind="ptm('button')['icon']" />
</slot>
</template>
</PVSButton>
2022-09-06 12:03:37 +00:00
</slot>
2022-12-08 11:04:25 +00:00
<PVSButton
ref="button"
type="button"
2023-05-30 14:17:32 +00:00
:class="cx('menuButton')"
2022-12-08 11:04:25 +00:00
:disabled="disabled"
aria-haspopup="true"
:aria-expanded="isExpanded"
:aria-controls="ariaId + '_overlay'"
@click="onDropdownButtonClick"
@keydown="onDropdownKeydown"
2023-05-02 08:00:39 +00:00
:pt="ptm('menuButton')"
v-bind="menuButtonProps"
:unstyled="unstyled"
data-pc-section="menubutton"
>
2023-04-19 07:50:39 +00:00
<template #icon="slotProps">
2023-06-06 08:14:14 +00:00
<slot name="menubuttonicon" :class="slotProps.class">
<component :is="menuButtonIcon ? 'span' : 'ChevronDownIcon'" :class="[menuButtonIcon, slotProps.class]" v-bind="ptm('menuButton')['icon']" />
</slot>
</template>
</PVSButton>
<PVSMenu ref="menu" :id="ariaId + '_overlay'" :model="model" :popup="true" :autoZIndex="autoZIndex" :baseZIndex="baseZIndex" :appendTo="appendTo" :unstyled="unstyled" :pt="ptm('menu')" />
2022-09-06 12:03:37 +00:00
</div>
</template>
<script>
import Button from 'primevue/button';
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,
emits: ['click'],
2022-12-08 11:04:25 +00:00
data() {
return {
isExpanded: false
};
2022-09-06 12:03:37 +00:00
},
mounted() {
this.$watch('$refs.menu.visible', (newValue) => {
this.isExpanded = newValue;
});
},
2022-09-06 12:03:37 +00:00
methods: {
onDropdownButtonClick(event) {
event.preventDefault();
2022-12-08 11:04:25 +00:00
this.$refs.menu.toggle({ currentTarget: this.$el, relatedTarget: this.$refs.button.$el });
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) {
event.preventDefault()
if (this.isExpanded) {
this.$refs.menu.hide(event);
}
this.$emit('click', event);
2022-09-06 12:03:37 +00:00
}
},
computed: {
ariaId() {
return UniqueComponentId();
},
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,
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>