UNPKG

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

65 lines (63 loc) 1.76 kB
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 const 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() { return looseEqual(this.value, this.computedLocalChecked) }, // Flags for form-radio-check mixin isRadio() { return true }, isCheck() { return false } }, watch: { // Radio Groups can only have a single value, so our watchers are simple computedLocalChecked() { this.$emit('input', this.computedLocalChecked) } }, methods: { handleChange({ target: { checked } }) { const 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) } } } })