@@ -13,63 +13,76 @@ export default {
13
13
const $slots = t . $slots
14
14
// Label
15
15
let legend = h ( false )
16
- if ( t . hasLabel || t . horizontal ) {
17
- // In horizontal mode, if there is no label, we still need to offset the input
18
- const tag = t . hasLabel ? 'legend' : 'div'
19
- const domProps = $slots . label ? { } : { innerHTML : t . label || '' }
16
+ if ( t . label || $slots . label || t . horizontal ) {
20
17
legend = h (
21
- tag ,
22
- { class : t . labelClasses , attrs : { id : t . labelId } , domProps : domProps } ,
23
- $slots . label
18
+ 'legend' ,
19
+ { class : t . labelClasses , attrs : { id : t . labelId } } ,
20
+ [ $slots . label || h ( 'span' , { domProps : { innerHTML : t . label || '' } } ) ]
24
21
)
25
22
}
26
- // Invalid feeback text (explicitly hidden if state is valid)
23
+ // Invalid feeback text
27
24
let invalidFeedback = h ( false )
28
- if ( t . hasInvalidFeedback ) {
29
- let domProps = { }
30
- if ( ! $slots [ 'invalid-feedback' ] && ! $slots [ 'feedback' ] ) {
31
- domProps = { innerHTML : t . invalidFeedback || t . feedback || '' }
32
- }
25
+ if ( t . invalidFeedback || t . feedback || $slots [ 'invalid-feedback' ] || $slots [ 'feedback' ] ) {
33
26
invalidFeedback = h (
34
27
'b-form-invalid-feedback' ,
35
28
{
29
+ directives : [
30
+ {
31
+ name : 'show' ,
32
+ rawName : 'v-show' ,
33
+ value : Boolean ( t . invalidFeedback || t . feedback || $slots [ 'invalid-feedback' ] || $slots [ 'feedback' ] ) ,
34
+ expression : "Boolean(t.invalidFeedback || t.feedback || $slots['invalid-feedback'] || $slots['feedback'])"
35
+ }
36
+ ] ,
36
37
attrs : {
37
38
id : t . invalidFeedbackId ,
38
39
role : 'alert' ,
39
40
'aria-live' : 'assertive' ,
40
41
'aria-atomic' : 'true'
41
- } ,
42
- domProps : domProps
42
+ }
43
43
} ,
44
- $slots [ 'invalid-feedback' ] || $slots [ 'feedback' ]
44
+ [
45
+ t . computedState === false
46
+ ? ( $slots [ 'invalid-feedback' ] || $slots [ 'feedback' ] || h ( 'span' , { domProps : { innerHTML : t . invalidFeedback || t . feedback || '' } } ) )
47
+ : h ( false )
48
+ ]
45
49
)
46
50
}
47
- // Valid feeback text (explicitly hidden if state is invalid)
51
+ // Valid feeback text
48
52
let validFeedback = h ( false )
49
- if ( t . hasValidFeedback ) {
50
- const domProps = $slots [ 'valid-feedback' ] ? { } : { innerHTML : t . validFeedback || '' }
53
+ if ( t . validFeedback || $slots [ 'valid-feedback' ] ) {
51
54
validFeedback = h (
52
55
'b-form-valid-feedback' ,
53
56
{
57
+ directives : [
58
+ {
59
+ name : 'show' ,
60
+ rawName : 'v-show' ,
61
+ value : Boolean ( t . validFeedback || $slots [ 'valid-feedback' ] ) ,
62
+ expression : "Boolean(t.validFeedback || $slots['valid-feedback'])"
63
+ }
64
+ ] ,
54
65
attrs : {
55
66
id : t . validFeedbackId ,
56
67
role : 'alert' ,
57
68
'aria-live' : 'assertive' ,
58
69
'aria-atomic' : 'true'
59
- } ,
60
- domProps : domProps
70
+ }
61
71
} ,
62
- $slots [ 'valid-feedback' ]
72
+ [
73
+ t . computedState === true
74
+ ? ( $slots [ 'valid-feedback' ] || h ( 'span' , { domProps : { innerHTML : t . validFeedback || '' } } ) )
75
+ : h ( false )
76
+ ]
63
77
)
64
78
}
65
79
// Form help text (description)
66
80
let description = h ( false )
67
- if ( t . hasDescription ) {
68
- const domProps = $slots [ 'description' ] ? { } : { innerHTML : t . description || '' }
81
+ if ( t . description || $slots [ 'description' ] ) {
69
82
description = h (
70
83
'b-form-text' ,
71
- { attrs : { id : t . descriptionId } , domProps : domProps } ,
72
- $slots [ 'description' ]
84
+ { attrs : { id : t . descriptionId } } ,
85
+ [ $slots [ 'description' ] || h ( 'span' , { domProps : { innerHTML : t . description || '' } } ) ]
73
86
)
74
87
}
75
88
// Build layout
@@ -116,10 +129,6 @@ export default {
116
129
type : String ,
117
130
default : null
118
131
} ,
119
- labelSize : {
120
- type : String ,
121
- default : null
122
- } ,
123
132
labelSrOnly : {
124
133
type : Boolean ,
125
134
default : false
@@ -151,20 +160,22 @@ export default {
151
160
}
152
161
} ,
153
162
computed : {
163
+ inputState ( ) {
164
+ return this . stateClass
165
+ } ,
154
166
groupClasses ( ) {
155
167
return [
156
168
'b-form-group' ,
157
169
'form-group' ,
158
170
this . validated ? 'was-validated' : null ,
159
- this . stateClass
171
+ this . inputState
160
172
]
161
173
} ,
162
174
labelClasses ( ) {
163
175
return [
164
- this . labelSrOnly ? 'sr-only' : ( this . labelSize ? 'col-form-label' : 'col-form- legend') ,
176
+ this . labelSrOnly ? 'sr-only' : 'col-form-legend' ,
165
177
this . labelLayout ,
166
178
this . labelAlignClass ,
167
- this . labelSizeClass ,
168
179
this . labelClass
169
180
]
170
181
} ,
@@ -180,55 +191,38 @@ export default {
180
191
}
181
192
return this . labelTextAlign ? `text-${ this . labelTextAlign } ` : null
182
193
} ,
183
- labelSizeClass ( ) {
184
- if ( this . labelSrOnly ) {
185
- return null
186
- }
187
- return this . labelSize ? `col-form-label-${ this . labelSize } ` : null
188
- } ,
189
194
inputLayoutClasses ( ) {
190
195
return [
191
196
this . horizontal ? `col-${ this . breakpoint } -${ 12 - this . labelCols } ` : 'col-12'
192
197
]
193
198
} ,
194
- hasLabel ( ) {
195
- return this . label || this . $slots [ 'label' ]
196
- } ,
197
- hasDescription ( ) {
198
- return this . description || this . $slots [ 'description' ]
199
- } ,
200
- hasInvalidFeedback ( ) {
201
- if ( this . computedState === true ) {
202
- // If the form-group state is explicityly valid, we return false
203
- return false
204
- }
205
- return this . invalidFeedback || this . feedback || this . $slots [ 'invalid-feedback' ] || this . $slots [ 'feedback' ]
206
- } ,
207
- hasValidFeedback ( ) {
208
- if ( this . computedState === false ) {
209
- // If the form-group state is explicityly invalid, we return false
210
- return false
211
- }
212
- return this . validFeedback || this . $slots [ 'valid-feedback' ]
213
- } ,
214
199
labelId ( ) {
215
- return this . hasLabel ? this . safeId ( '_BV_label_' ) : null
200
+ return ( this . label || this . $slots [ 'label' ] ) ? this . safeId ( '_BV_label_' ) : null
216
201
} ,
217
202
descriptionId ( ) {
218
- return this . hasDescription ? this . safeId ( '_BV_description_' ) : null
203
+ if ( this . description || this . $slots [ 'description' ] ) {
204
+ return this . safeId ( '_BV_description_' )
205
+ }
206
+ return null
219
207
} ,
220
208
invalidFeedbackId ( ) {
221
- return this . hasInvalidFeedback ? this . safeId ( '_BV_feedback_invalid_' ) : null
209
+ if ( this . invalidFeedback || this . feedback || this . $slots [ 'invalid-feedback' ] || this . $slots [ 'feedback' ] ) {
210
+ return this . safeId ( '_BV_feedback_invalid_' )
211
+ }
212
+ return null
222
213
} ,
223
214
validFeedbackId ( ) {
224
- return this . hasValidFeedback ? this . safeId ( '_BV_feedback_valid_' ) : null
215
+ if ( this . validFeedback || this . $slots [ 'valid-feedback' ] ) {
216
+ return this . safeId ( '_BV_feedback_valid_' )
217
+ }
218
+ return null
225
219
} ,
226
220
describedByIds ( ) {
227
221
return [
228
222
this . labelId ,
229
223
this . descriptionId ,
230
- this . invalidFeedbackId ,
231
- this . validFeedbackId
224
+ this . computedState === false ? this . invalidFeedbackId : null ,
225
+ this . computedState === true ? this . validFeedbackId : null
232
226
] . filter ( i => i ) . join ( ' ' ) || null
233
227
}
234
228
}
0 commit comments