primevue-mirror/components/lib/fieldset/Fieldset.vue

92 lines
3.0 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2023-05-29 09:19:55 +00:00
<fieldset :class="cx('root')" v-bind="ptm('root')" data-pc-name="fieldset">
2023-05-19 11:14:50 +00:00
<legend :class="cx('legend')" v-bind="ptm('legend')">
2022-09-14 11:26:01 +00:00
<slot v-if="!toggleable" name="legend">
2023-05-19 11:14:50 +00:00
<span :id="ariaId + '_header'" :class="cx('legendtitle')" v-bind="ptm('legendtitle')">{{ legend }}</span>
2022-09-06 12:03:37 +00:00
</slot>
2022-12-08 11:04:25 +00:00
<a
v-if="toggleable"
:id="ariaId + '_header'"
v-ripple
tabindex="0"
role="button"
:aria-controls="ariaId + '_content'"
:aria-expanded="!d_collapsed"
:aria-label="buttonAriaLabel"
@click="toggle"
@keydown="onKeyDown"
2023-03-24 15:07:46 +00:00
v-bind="{ ...toggleButtonProps, ...ptm('toggler') }"
2022-12-08 11:04:25 +00:00
>
2023-03-24 15:07:46 +00:00
<slot name="togglericon" :collapsed="d_collapsed">
2023-05-19 11:14:50 +00:00
<component :is="d_collapsed ? 'PlusIcon' : 'MinusIcon'" :class="cx('togglericon')" v-bind="ptm('togglericon')" />
2023-03-24 15:07:46 +00:00
</slot>
2022-09-06 12:03:37 +00:00
<slot name="legend">
2023-05-19 11:14:50 +00:00
<span :class="cx('legendtitle')" v-bind="ptm('legendtitle')">{{ legend }}</span>
2022-09-06 12:03:37 +00:00
</slot>
</a>
</legend>
2023-08-02 12:00:59 +00:00
<transition name="p-toggleable-content" v-bind="ptm('transition')">
2023-05-19 11:14:50 +00:00
<div v-show="!d_collapsed" :id="ariaId + '_content'" :class="cx('toggleablecontent')" role="region" :aria-labelledby="ariaId + '_header'" v-bind="ptm('toggleablecontent')">
<div :class="cx('content')" v-bind="ptm('content')">
2022-09-06 12:03:37 +00:00
<slot></slot>
</div>
</div>
</transition>
</fieldset>
</template>
<script>
import MinusIcon from 'primevue/icons/minus';
import PlusIcon from 'primevue/icons/plus';
2023-04-14 08:03:50 +00:00
import Ripple from 'primevue/ripple';
2022-12-08 11:04:25 +00:00
import { UniqueComponentId } from 'primevue/utils';
2023-05-19 12:16:12 +00:00
import BaseFieldset from './BaseFieldset.vue';
2022-09-06 12:03:37 +00:00
export default {
name: 'Fieldset',
2023-05-19 10:44:25 +00:00
extends: BaseFieldset,
2022-09-06 12:03:37 +00:00
emits: ['update:collapsed', 'toggle'],
data() {
return {
2022-09-14 11:26:01 +00:00
d_collapsed: this.collapsed
};
2022-09-06 12:03:37 +00:00
},
watch: {
collapsed(newValue) {
this.d_collapsed = newValue;
}
},
methods: {
toggle(event) {
this.d_collapsed = !this.d_collapsed;
this.$emit('update:collapsed', this.d_collapsed);
this.$emit('toggle', {
originalEvent: event,
value: this.d_collapsed
});
2022-09-14 11:26:01 +00:00
},
onKeyDown(event) {
if (event.code === 'Enter' || event.code === 'Space') {
this.toggle(event);
event.preventDefault();
}
2022-09-06 12:03:37 +00:00
}
},
2022-09-14 11:26:01 +00:00
computed: {
2022-09-06 12:03:37 +00:00
ariaId() {
return UniqueComponentId();
2022-12-08 11:04:25 +00:00
},
buttonAriaLabel() {
2023-11-30 20:08:56 +00:00
return this.toggleButtonProps && this.toggleButtonProps.ariaLabel ? this.toggleButtonProps.ariaLabel : this.legend;
2022-09-06 12:03:37 +00:00
}
},
directives: {
2022-09-14 11:26:01 +00:00
ripple: Ripple
},
components: {
PlusIcon,
MinusIcon
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>