Skip to content

Commit 1d85839

Browse files
authored
fix: user supplied prop function detection (closes bootstrap-vue#6112) (bootstrap-vue#6113)
* fix(b-form-input/b-form-textarea): v-model handling * Update form-text.js * Update form-text.js * Update form-text.js * Update form-text.js * Update form-text.js * Update form-text.js * Update form-text.js * Update form-text.js * Update form-text.js * Update form-text.js * fix: user supplied prop function detection * Update calendar.spec.js * Update form-text.js * fix: further improve user supplied prop fucntion detection * Revert "fix: further improve user supplied prop fucntion detection" This reverts commit 86bbb7f.
1 parent c375ce9 commit 1d85839

File tree

7 files changed

+314
-228
lines changed

7 files changed

+314
-228
lines changed

src/components/calendar/calendar.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,14 @@ export const BCalendar = Vue.extend({
342342
},
343343
computedDateDisabledFn() {
344344
const { dateDisabledFn } = this
345-
return dateDisabledFn.name !== 'default' ? dateDisabledFn : () => false
345+
return dateDisabledFn.name !== props.dateDisabledFn.default.name
346+
? dateDisabledFn
347+
: () => false
346348
},
347349
// TODO: Change `dateInfoFn` to handle events and notes as well as classes
348350
computedDateInfoFn() {
349351
const { dateInfoFn } = this
350-
return dateInfoFn.name !== 'default' ? dateInfoFn : () => ({})
352+
return dateInfoFn.name !== props.dateInfoFn.default.name ? dateInfoFn : () => ({})
351353
},
352354
calendarLocale() {
353355
// This locale enforces the gregorian calendar (for use in formatter functions)

src/components/calendar/calendar.spec.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,4 +377,70 @@ describe('calendar', () => {
377377
expect($buttons.at(3).classes()).toContain('btn-outline-primary')
378378
expect($buttons.at(4).classes()).toContain('btn-outline-primary')
379379
})
380+
381+
it('disables dates based on `date-disabled-fn` prop', async () => {
382+
const wrapper = mount(BCalendar, {
383+
attachTo: createContainer(),
384+
propsData: {
385+
value: '2020-01-01',
386+
dateDisabledFn(ymd) {
387+
return ymd === '2020-01-02'
388+
}
389+
}
390+
})
391+
392+
expect(wrapper.vm).toBeDefined()
393+
await waitNT(wrapper.vm)
394+
await waitRAF()
395+
396+
const $grid = wrapper.find('[role="application"]')
397+
expect($grid.exists()).toBe(true)
398+
399+
let $cell = $grid.find('[data-date="2020-01-01"]')
400+
expect($cell.exists()).toBe(true)
401+
expect($cell.attributes('aria-disabled')).toBeUndefined()
402+
403+
$cell = $grid.find('[data-date="2020-01-02"]')
404+
expect($cell.exists()).toBe(true)
405+
expect($cell.attributes('aria-disabled')).toEqual('true')
406+
407+
$cell = $grid.find('[data-date="2020-01-03"]')
408+
expect($cell.exists()).toBe(true)
409+
expect($cell.attributes('aria-disabled')).toBeUndefined()
410+
411+
wrapper.destroy()
412+
})
413+
414+
it('applies classes on dates based on `date-info-fn` prop', async () => {
415+
const wrapper = mount(BCalendar, {
416+
attachTo: createContainer(),
417+
propsData: {
418+
value: '2020-01-01',
419+
dateInfoFn(ymd) {
420+
return ymd === '2020-01-02' ? 'my-info' : null
421+
}
422+
}
423+
})
424+
425+
expect(wrapper.vm).toBeDefined()
426+
await waitNT(wrapper.vm)
427+
await waitRAF()
428+
429+
const $grid = wrapper.find('[role="application"]')
430+
expect($grid.exists()).toBe(true)
431+
432+
let $cell = $grid.find('[data-date="2020-01-01"]')
433+
expect($cell.exists()).toBe(true)
434+
expect($cell.classes()).not.toContain('my-info')
435+
436+
$cell = $grid.find('[data-date="2020-01-02"]')
437+
expect($cell.exists()).toBe(true)
438+
expect($cell.classes()).toContain('my-info')
439+
440+
$cell = $grid.find('[data-date="2020-01-03"]')
441+
expect($cell.exists()).toBe(true)
442+
expect($cell.classes()).not.toContain('my-info')
443+
444+
wrapper.destroy()
445+
})
380446
})

src/components/form-file/form-file.js

Lines changed: 79 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,83 @@ const getAllFileEntriesInDirectory = (directoryReader, path = '') =>
108108
readDirectoryEntries()
109109
})
110110

111+
// --- Props ---
112+
113+
const props = makePropsConfigurable(
114+
{
115+
...formControlProps,
116+
...formCustomProps,
117+
...formStateProps,
118+
...formSizeProps,
119+
value: {
120+
type: [File, Array],
121+
default: null,
122+
validator(value) {
123+
/* istanbul ignore next */
124+
if (value === '') {
125+
warn(VALUE_EMPTY_DEPRECATED_MSG, NAME_FORM_FILE)
126+
return true
127+
}
128+
return isUndefinedOrNull(value) || isValidValue(value)
129+
}
130+
},
131+
accept: {
132+
type: String,
133+
default: ''
134+
},
135+
// Instruct input to capture from camera
136+
capture: {
137+
type: Boolean,
138+
default: false
139+
},
140+
placeholder: {
141+
type: String,
142+
default: 'No file chosen'
143+
},
144+
browseText: {
145+
type: String,
146+
default: 'Browse'
147+
},
148+
dropPlaceholder: {
149+
type: String,
150+
default: 'Drop files here'
151+
},
152+
noDropPlaceholder: {
153+
type: String,
154+
default: 'Not allowed'
155+
},
156+
multiple: {
157+
type: Boolean,
158+
default: false
159+
},
160+
directory: {
161+
type: Boolean,
162+
default: false
163+
},
164+
// TODO:
165+
// Should we deprecate this and only support flat file structures?
166+
// Nested file structures are only supported when files are dropped
167+
// A Chromium "bug" prevents `webkitEntries` from being populated
168+
// on the file input's `change` event and is marked as "WontFix"
169+
// Mozilla implemented the behavior the same way as Chromium
170+
// See: https://bugs.chromium.org/p/chromium/issues/detail?id=138987
171+
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1326031
172+
noTraverse: {
173+
type: Boolean,
174+
default: false
175+
},
176+
noDrop: {
177+
type: Boolean,
178+
default: false
179+
},
180+
fileNameFormatter: {
181+
type: Function
182+
// default: null
183+
}
184+
},
185+
NAME_FORM_FILE
186+
)
187+
111188
// @vue/component
112189
export const BFormFile = /*#__PURE__*/ Vue.extend({
113190
name: NAME_FORM_FILE,
@@ -124,80 +201,7 @@ export const BFormFile = /*#__PURE__*/ Vue.extend({
124201
prop: 'value',
125202
event: 'input'
126203
},
127-
props: makePropsConfigurable(
128-
{
129-
...formControlProps,
130-
...formCustomProps,
131-
...formStateProps,
132-
...formSizeProps,
133-
value: {
134-
type: [File, Array],
135-
default: null,
136-
validator(value) {
137-
/* istanbul ignore next */
138-
if (value === '') {
139-
warn(VALUE_EMPTY_DEPRECATED_MSG, NAME_FORM_FILE)
140-
return true
141-
}
142-
return isUndefinedOrNull(value) || isValidValue(value)
143-
}
144-
},
145-
accept: {
146-
type: String,
147-
default: ''
148-
},
149-
// Instruct input to capture from camera
150-
capture: {
151-
type: Boolean,
152-
default: false
153-
},
154-
placeholder: {
155-
type: String,
156-
default: 'No file chosen'
157-
},
158-
browseText: {
159-
type: String,
160-
default: 'Browse'
161-
},
162-
dropPlaceholder: {
163-
type: String,
164-
default: 'Drop files here'
165-
},
166-
noDropPlaceholder: {
167-
type: String,
168-
default: 'Not allowed'
169-
},
170-
multiple: {
171-
type: Boolean,
172-
default: false
173-
},
174-
directory: {
175-
type: Boolean,
176-
default: false
177-
},
178-
// TODO:
179-
// Should we deprecate this and only support flat file structures?
180-
// Nested file structures are only supported when files are dropped
181-
// A Chromium "bug" prevents `webkitEntries` from being populated
182-
// on the file input's `change` event and is marked as "WontFix"
183-
// Mozilla implemented the behavior the same way as Chromium
184-
// See: https://bugs.chromium.org/p/chromium/issues/detail?id=138987
185-
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1326031
186-
noTraverse: {
187-
type: Boolean,
188-
default: false
189-
},
190-
noDrop: {
191-
type: Boolean,
192-
default: false
193-
},
194-
fileNameFormatter: {
195-
type: Function
196-
// default: null
197-
}
198-
},
199-
NAME_FORM_FILE
200-
),
204+
props,
201205
data() {
202206
return {
203207
files: [],
@@ -269,7 +273,7 @@ export const BFormFile = /*#__PURE__*/ Vue.extend({
269273
},
270274
computedFileNameFormatter() {
271275
const { fileNameFormatter } = this
272-
return fileNameFormatter.name !== 'default'
276+
return fileNameFormatter.name !== props.fileNameFormatter.default.name
273277
? fileNameFormatter
274278
: this.defaultFileNameFormatter
275279
},

src/components/form-spinbutton/form-spinbutton.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ export const BFormSpinbutton = /*#__PURE__*/ Vue.extend({
223223
},
224224
computedFormatter() {
225225
const { formatterFn } = this
226-
return formatterFn.name !== 'default' ? formatterFn : this.defaultFormatter
226+
return formatterFn.name !== props.formatterFn.default.name
227+
? formatterFn
228+
: this.defaultFormatter
227229
},
228230
computedAttrs() {
229231
return {

0 commit comments

Comments
 (0)