bootstrap-vue
Version:
With more than 85 components, over 45 available plugins, several directives, and 1000+ icons, BootstrapVue provides one of the most comprehensive implementations of the Bootstrap v4 component and grid system available for Vue.js v2.6, complete with extens
59 lines (56 loc) • 1.87 kB
JavaScript
import Vue from '../../vue';
import { NAME_FORM_RADIO } from '../../constants/components';
import idMixin from '../../mixins/id';
import formMixin from '../../mixins/form';
import formStateMixin from '../../mixins/form-state';
import formSizeMixin from '../../mixins/form-size';
import formRadioCheckMixin from '../../mixins/form-radio-check';
import looseEqual from '../../utils/loose-equal'; // @vue/component
export var BFormRadio = /*#__PURE__*/Vue.extend({
name: NAME_FORM_RADIO,
mixins: [idMixin, formRadioCheckMixin, // Includes shared render function
formMixin, formSizeMixin, formStateMixin],
inject: {
bvGroup: {
from: 'bvRadioGroup',
default: false
}
},
props: {
checked: {
// v-model
// type: [String, Number, Boolean, Object],
default: null
}
},
computed: {
// Radio Groups can only have a single value, so determining if checked is simple
isChecked: function isChecked() {
return looseEqual(this.value, this.computedLocalChecked);
},
// Flags for form-radio-check mixin
isRadio: function isRadio() {
return true;
},
isCheck: function isCheck() {
return false;
}
},
watch: {
// Radio Groups can only have a single value, so our watchers are simple
computedLocalChecked: function computedLocalChecked() {
this.$emit('input', this.computedLocalChecked);
}
},
methods: {
handleChange: function handleChange(_ref) {
var checked = _ref.target.checked;
var value = this.value;
this.computedLocalChecked = value; // Change is only emitted on user interaction
this.$emit('change', checked ? value : null); // If this is a child of form-radio-group, we emit a change event on it as well
if (this.isGroup) {
this.bvGroup.$emit('change', checked ? value : null);
}
}
}
});