2022-09-06 12:03:37 +00:00
|
|
|
<template>
|
2024-01-30 14:35:32 +00:00
|
|
|
<div :class="cx('root')" v-bind="getPTOptions('root')" :data-p-highlight="checked" :data-p-disabled="disabled">
|
2024-01-12 07:07:55 +00:00
|
|
|
<input
|
|
|
|
:id="inputId"
|
|
|
|
type="radio"
|
|
|
|
:class="[cx('input'), inputClass]"
|
|
|
|
:style="inputStyle"
|
|
|
|
:value="value"
|
|
|
|
:name="name"
|
|
|
|
:checked="checked"
|
|
|
|
:tabindex="tabindex"
|
|
|
|
:disabled="disabled"
|
|
|
|
:readonly="readonly"
|
|
|
|
:aria-labelledby="ariaLabelledby"
|
|
|
|
:aria-label="ariaLabel"
|
|
|
|
@focus="onFocus"
|
|
|
|
@blur="onBlur"
|
|
|
|
@change="onChange"
|
|
|
|
v-bind="getPTOptions('input')"
|
|
|
|
/>
|
|
|
|
<div :class="cx('box')" v-bind="getPTOptions('box')">
|
|
|
|
<div :class="cx('icon')" v-bind="getPTOptions('icon')"></div>
|
2022-09-06 12:03:37 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2022-09-14 11:26:01 +00:00
|
|
|
import { ObjectUtils } from 'primevue/utils';
|
2023-05-24 12:29:06 +00:00
|
|
|
import BaseRadioButton from './BaseRadioButton.vue';
|
2022-09-06 12:03:37 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'RadioButton',
|
2023-05-24 12:29:06 +00:00
|
|
|
extends: BaseRadioButton,
|
2024-02-11 23:48:21 +00:00
|
|
|
inheritAttrs: false,
|
2024-01-12 07:07:55 +00:00
|
|
|
emits: ['update:modelValue', 'change', 'focus', 'blur'],
|
2022-09-06 12:03:37 +00:00
|
|
|
methods: {
|
2024-01-12 07:07:55 +00:00
|
|
|
getPTOptions(key) {
|
2024-02-11 23:48:21 +00:00
|
|
|
const _ptm = key === 'root' ? this.ptmi : this.ptm;
|
|
|
|
|
|
|
|
return _ptm(key, {
|
2024-01-12 07:07:55 +00:00
|
|
|
context: {
|
|
|
|
checked: this.checked,
|
|
|
|
disabled: this.disabled
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
2024-01-12 07:07:55 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
onChange(event) {
|
|
|
|
if (!this.disabled && !this.readonly) {
|
2024-01-14 22:25:39 +00:00
|
|
|
const newModelValue = this.binary ? !this.checked : this.value;
|
|
|
|
|
|
|
|
this.$emit('update:modelValue', newModelValue);
|
2024-01-12 07:07:55 +00:00
|
|
|
this.$emit('change', event);
|
2022-09-06 12:03:37 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
onFocus(event) {
|
|
|
|
this.$emit('focus', event);
|
|
|
|
},
|
|
|
|
onBlur(event) {
|
|
|
|
this.$emit('blur', event);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
checked() {
|
2024-01-14 22:25:39 +00:00
|
|
|
return this.modelValue != null && (this.binary ? !!this.modelValue : ObjectUtils.equals(this.modelValue, this.value));
|
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>
|