@@ -4,14 +4,27 @@ import { makePropsConfigurable } from '../utils/config'
44import { htmlOrText } from '../utils/html'
55import { BFormCheckbox } from '../components/form-checkbox/form-checkbox'
66import { BFormRadio } from '../components/form-radio/form-radio'
7+ import formControlMixin , { props as formControlProps } from './form-control'
78import formCustomMixin , { props as formCustomProps } from './form-custom'
9+ import formOptionsMixin , { props as formOptionsProps } from './form-options'
10+ import formSizeMixin , { props as formSizeProps } from './form-size'
11+ import formStateMixin , { props as formStateProps } from './form-state'
12+ import idMixin from './id'
813import normalizeSlotMixin from './normalize-slot'
914
1015// --- Props ---
1116
1217export const props = makePropsConfigurable (
1318 {
19+ ...formControlProps ,
20+ ...formOptionsProps ,
21+ ...formSizeProps ,
22+ ...formStateProps ,
1423 ...formCustomProps ,
24+ checked : {
25+ // type: [Boolean, Number, Object, String]
26+ default : null
27+ } ,
1528 validated : {
1629 type : Boolean ,
1730 default : false
@@ -39,14 +52,28 @@ export const props = makePropsConfigurable(
3952)
4053
4154// --- Mixin ---
55+
4256// @vue /component
4357export default {
44- mixins : [ formCustomMixin , normalizeSlotMixin ] ,
58+ mixins : [
59+ idMixin ,
60+ normalizeSlotMixin ,
61+ formControlMixin ,
62+ formOptionsMixin ,
63+ formSizeMixin ,
64+ formStateMixin ,
65+ formCustomMixin
66+ ] ,
4567 model : {
4668 prop : 'checked' ,
4769 event : 'input'
4870 } ,
4971 props,
72+ data ( ) {
73+ return {
74+ localChecked : this . checked
75+ }
76+ } ,
5077 computed : {
5178 inline ( ) {
5279 return ! this . stacked
@@ -57,28 +84,28 @@ export default {
5784 return this . name || this . safeId ( )
5885 } ,
5986 groupClasses ( ) {
87+ const { inline, size, validated } = this
88+
89+ let classes = { 'was-validated' : validated }
6090 if ( this . buttons ) {
61- return [
91+ classes = [
92+ classes ,
6293 'btn-group-toggle' ,
63- this . inline ? 'btn-group' : 'btn-group-vertical' ,
64- this . size ? `btn-group-${ this . size } ` : '' ,
65- this . validated ? `was-validated` : ''
94+ {
95+ 'btn-group' : inline ,
96+ 'btn-group-vertical' : ! inline ,
97+ [ `btn-group-${ size } ` ] : ! ! size
98+ }
6699 ]
67100 }
68- return [ this . validated ? `was-validated` : '' ]
69- } ,
70- computedAriaInvalid ( ) {
71- const ariaInvalid = this . ariaInvalid
72- if ( ariaInvalid === true || ariaInvalid === 'true' || ariaInvalid === '' ) {
73- return 'true'
74- }
75- return this . computedState === false ? 'true' : null
101+
102+ return classes
76103 }
77104 } ,
78105 watch : {
79- checked ( newVal ) {
80- if ( ! looseEqual ( newVal , this . localChecked ) ) {
81- this . localChecked = newVal
106+ checked ( newValue ) {
107+ if ( ! looseEqual ( newValue , this . localChecked ) ) {
108+ this . localChecked = newValue
82109 }
83110 } ,
84111 localChecked ( newValue , oldValue ) {
@@ -88,11 +115,14 @@ export default {
88115 }
89116 } ,
90117 render ( h ) {
118+ const { isRadioGroup } = this
119+ const optionComponent = isRadioGroup ? BFormRadio : BFormCheckbox
120+
91121 const $inputs = this . formOptions . map ( ( option , index ) => {
92122 const key = `BV_option_${ index } `
93123
94124 return h (
95- this . isRadioGroup ? BFormRadio : BFormCheckbox ,
125+ optionComponent ,
96126 {
97127 props : {
98128 id : this . safeId ( key ) ,
@@ -116,7 +146,7 @@ export default {
116146 class : [ this . groupClasses , 'bv-no-focus-ring' ] ,
117147 attrs : {
118148 id : this . safeId ( ) ,
119- role : this . isRadioGroup ? 'radiogroup' : 'group' ,
149+ role : isRadioGroup ? 'radiogroup' : 'group' ,
120150 // Add `tabindex="-1"` to allow group to be focused if needed by screen readers
121151 tabindex : '-1' ,
122152 'aria-required' : this . required ? 'true' : null ,
0 commit comments