primevue-mirror/components/lib/datatable/RowRadioButton.vue

80 lines
2.5 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
<div :class="cx('radiobuttonWrapper')" @click="onClick" v-bind="getColumnPT('radiobuttonWrapper')">
<div class="p-hidden-accessible" v-bind="getColumnPT('hiddenInputWrapper')" :data-p-hidden-accessible="true">
<input ref="input" type="radio" :checked="checked" :disabled="$attrs.disabled" :name="name" tabindex="0" @focus="onFocus($event)" @blur="onBlur($event)" @keydown.space.prevent="onClick" v-bind="getColumnPT('hiddenInput')" />
2022-12-08 11:04:25 +00:00
</div>
<div ref="box" :class="cx('radiobutton')" v-bind="getColumnPT('radiobutton')">
<div :class="cx('radiobuttonIcon')" v-bind="getColumnPT('radiobuttonIcon')"></div>
2022-09-06 12:03:37 +00:00
</div>
</div>
</template>
<script>
2023-05-08 14:08:06 +00:00
import BaseComponent from 'primevue/basecomponent';
2022-12-08 11:04:25 +00:00
import { DomHandler } from 'primevue/utils';
import { mergeProps } from 'vue';
2022-12-08 11:04:25 +00:00
2022-09-06 12:03:37 +00:00
export default {
name: 'RowRadioButton',
hostName: 'DataTable',
2023-05-08 14:08:06 +00:00
extends: BaseComponent,
2022-09-06 12:03:37 +00:00
inheritAttrs: false,
emits: ['change'],
props: {
2022-09-14 11:26:01 +00:00
value: null,
2022-12-08 11:04:25 +00:00
checked: null,
name: null,
column: null,
index: {
type: Number,
default: null
}
2022-09-06 12:03:37 +00:00
},
data() {
return {
focused: false
};
},
methods: {
getColumnPT(key) {
const columnMetaData = {
props: this.column.props,
parent: {
props: this.$props,
state: this.$data
},
2023-05-08 14:08:06 +00:00
context: {
index: this.index,
2023-05-08 14:08:06 +00:00
checked: this.checked,
focused: this.focused,
disabled: this.$attrs.disabled
}
};
return mergeProps(this.ptm(`column.${key}`, { column: columnMetaData }), this.ptm(`column.${key}`, columnMetaData), this.ptmo(this.getColumnProp(), key, columnMetaData));
2023-05-08 14:08:06 +00:00
},
getColumnProp() {
return this.column.props && this.column.props.pt ? this.column.props.pt : undefined; //@todo:
},
2022-09-06 12:03:37 +00:00
onClick(event) {
if (!this.disabled) {
if (!this.checked) {
this.$emit('change', {
originalEvent: event,
data: this.value
});
2022-12-08 11:04:25 +00:00
DomHandler.focus(this.$refs.input);
2022-09-06 12:03:37 +00:00
}
}
},
onFocus() {
this.focused = true;
},
onBlur() {
this.focused = false;
}
}
2022-09-14 11:26:01 +00:00
};
2022-09-06 12:03:37 +00:00
</script>