primevue-mirror/components/datatable/RowRadioButton.vue

51 lines
1.4 KiB
Vue
Raw Normal View History

2022-09-06 12:03:37 +00:00
<template>
2022-12-08 11:04:25 +00:00
<div :class="['p-radiobutton p-component', { 'p-radiobutton-focused': focused }]" @click="onClick">
<div class="p-hidden-accessible">
<input ref="input" type="radio" :checked="checked" :disabled="$attrs.disabled" :name="name" tabindex="0" @focus="onFocus($event)" @blur="onBlur($event)" @keydown.space.prevent="onClick" />
</div>
<div ref="box" :class="['p-radiobutton-box p-component', { 'p-highlight': checked, 'p-disabled': $attrs.disabled, 'p-focus': focused }]">
2022-09-06 12:03:37 +00:00
<div class="p-radiobutton-icon"></div>
</div>
</div>
</template>
<script>
2022-12-08 11:04:25 +00:00
import { DomHandler } from 'primevue/utils';
2022-09-06 12:03:37 +00:00
export default {
name: 'RowRadioButton',
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
2022-09-06 12:03:37 +00:00
},
data() {
return {
focused: false
};
},
methods: {
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>