@@ -19,33 +19,33 @@ import BFormValidFeedback from '../form/form-valid-feedback'
19
19
// Selector for finding first input in the form-group
20
20
const SELECTOR = 'input:not(:disabled),textarea:not(:disabled),select:not(:disabled)'
21
21
22
- // Breakpoint names for label-cols and label-align props
23
- const BREAKPOINTS = getBreakpointsUp ( )
24
-
25
22
// Memoize this function to return cached values to save time in computed functions
26
23
const makePropName = memoize ( ( breakpoint = '' , prefix ) => {
27
24
return `${ prefix } ${ upperFirst ( breakpoint ) } `
28
25
} )
29
26
30
27
// Generate the labelCol breakpoint props
31
- const bpLabelColProps = BREAKPOINTS . reduce ( ( props , breakpoint ) => {
32
- // i.e. label-cols, label-cols-sm, label-cols-md, ...
33
- props [ makePropName ( breakpoint , 'labelCols' ) ] = {
34
- type : [ Number , String , Boolean ] ,
35
- default : breakpoint ? false : null
36
- }
37
- return props
38
- } , create ( null ) )
39
-
28
+ const bpLabelColProps = ( ) => {
29
+ return getBreakpointsUp ( ) . reduce ( ( props , breakpoint ) => {
30
+ // i.e. label-cols, label-cols-sm, label-cols-md, ...
31
+ props [ makePropName ( breakpoint , 'labelCols' ) ] = {
32
+ type : [ Number , String , Boolean ] ,
33
+ default : breakpoint ? false : null
34
+ }
35
+ return props
36
+ } , create ( null ) )
37
+ }
40
38
// Generate the labelAlign breakpoint props
41
- const bpLabelAlignProps = BREAKPOINTS . reduce ( ( props , breakpoint ) => {
42
- // label-align, label-align-sm, label-align-md, ...
43
- props [ makePropName ( breakpoint , 'labelAlign' ) ] = {
44
- type : String , // left, right, center
45
- default : null
46
- }
47
- return props
48
- } , create ( null ) )
39
+ const bpLabelAlignProps = ( ) => {
40
+ return getBreakpointsUp ( ) . reduce ( ( props , breakpoint ) => {
41
+ // label-align, label-align-sm, label-align-md, ...
42
+ props [ makePropName ( breakpoint , 'labelAlign' ) ] = {
43
+ type : String , // left, right, center
44
+ default : null
45
+ }
46
+ return props
47
+ } , create ( null ) )
48
+ }
49
49
50
50
// render helper functions (here rather than polluting the instance with more methods)
51
51
function renderInvalidFeedback ( h , ctx ) {
@@ -233,9 +233,9 @@ export default {
233
233
default : false
234
234
} ,
235
235
// label-cols prop and all label-cols-{bp} props
236
- ...bpLabelColProps ,
236
+ ...bpLabelColProps ( ) ,
237
237
// label-align prop and all label-align-{bp} props
238
- ...bpLabelAlignProps ,
238
+ ...bpLabelAlignProps ( ) ,
239
239
horizontal : {
240
240
// Deprecated
241
241
type : Boolean ,
@@ -250,8 +250,13 @@ export default {
250
250
}
251
251
} ,
252
252
computed : {
253
+ breakpoints ( ) {
254
+ // This will be cached the first time it is called
255
+ return getBreakpointsUp ( )
256
+ } ,
253
257
labelColProps ( ) {
254
258
const props = { }
259
+ const breakpoints = this . breakpoints
255
260
/* istanbul ignore next: deprecated */
256
261
if ( this . horizontal ) {
257
262
// Deprecated setting of horizontal/breakpoint props
@@ -260,13 +265,13 @@ export default {
260
265
"b-form-group: Props 'horizontal' and 'breakpoint' are deprecated. Use 'label-cols(-{breakpoint})' props instead."
261
266
)
262
267
// Legacy default is breakpoint sm and cols 3
263
- const bp = this . breakpoint || BREAKPOINTS [ 1 ] // 'sm'
268
+ const bp = this . breakpoint || breakpoints [ 1 ] // 'sm'
264
269
const cols = parseInt ( this . labelCols , 10 ) || 3
265
270
props [ bp ] = cols > 0 ? cols : 3
266
271
// We then return the single breakpoint prop for legacy compatability
267
272
return props
268
273
}
269
- BREAKPOINTS . forEach ( breakpoint => {
274
+ breakpoints . forEach ( breakpoint => {
270
275
// Grab the value if the label column breakpoint prop
271
276
let propVal = this [ makePropName ( breakpoint , 'labelCols' ) ]
272
277
// Handle case where the prop's value is an empty string, which represents true
@@ -289,7 +294,8 @@ export default {
289
294
} ,
290
295
labelAlignClasses ( ) {
291
296
const classes = [ ]
292
- BREAKPOINTS . forEach ( breakpoint => {
297
+ const breakpoints = this . breakpoints
298
+ breakpoints . forEach ( breakpoint => {
293
299
// assemble the label column breakpoint align classes
294
300
const propVal = this [ makePropName ( breakpoint , 'labelAlign' ) ] || null
295
301
if ( propVal ) {
0 commit comments