8000 fix: user supplied prop function detection (closes #6112) by jacobmllr95 · Pull Request #6113 · bootstrap-vue/bootstrap-vue · GitHub
[go: up one dir, main page]

Skip to content

fix: user supplied prop function detection (closes #6112) #6113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Dec 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/components/calendar/calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,14 @@ export const BCalendar = Vue.extend({
},
computedDateDisabledFn() {
const { dateDisabledFn } = this
return dateDisabledFn.name !== 'default' ? dateDisabledFn : () => false
return dateDisabledFn.name !== props.dateDisabledFn.default.name
? dateDisabledFn
: () => false
},
// TODO: Change `dateInfoFn` to handle events and notes as well as classes
computedDateInfoFn() {
const { dateInfoFn } = this
return dateInfoFn.name !== 'default' ? dateInfoFn : () => ({})
return dateInfoFn.name !== props.dateInfoFn.default.name ? dateInfoFn : () => ({})
},
calendarLocale() {
// This locale enforces the gregorian calendar (for use in formatter functions)
Expand Down
66 changes: 66 additions & 0 deletions src/components/calendar/calendar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,70 @@ describe('calendar', () => {
expect($buttons.at(3).classes()).toContain('btn-outline-primary')
expect($buttons.at(4).classes()).toContain('btn-outline-primary')
})

it('disables dates based on `date-disabled-fn` prop', async () => {
const wrapper = mount(BCalendar, {
attachTo: createContainer(),
propsData: {
value: '2020-01-01',
dateDisabledFn(ymd) {
return ymd === '2020-01-02'
}
}
})

expect(wrapper.vm).toBeDefined()
await waitNT(wrapper.vm)
await waitRAF()

const $grid = wrapper.find('[role="application"]')
expect($grid.exists()).toBe(true)

let $cell = $grid.find('[data-date="2020-01-01"]')
expect($cell.exists()).toBe(true)
expect($cell.attributes('aria-disabled')).toBeUndefined()

$cell = $grid.find('[data-date="2020-01-02"]')
expect($cell.exists()).toBe(true)
expect($cell.attributes('aria-disabled')).toEqual('true')

$cell = $grid.find('[data-date="2020-01-03"]')
expect($cell.exists()).toBe(true)
expect($cell.attributes('aria-disabled')).toBeUndefined()

wrapper.destroy()
})

it('applies classes on dates based on `date-info-fn` prop', async () => {
const wrapper = mount(BCalendar, {
attachTo: createContainer(),
propsData: {
value: '2020-01-01',
dateInfoFn(ymd) {
return ymd === '2020-01-02' ? 'my-info' : null
}
}
})

expect(wrapper.vm).toBeDefined()
await waitNT(wrapper.vm)
await waitRAF()

const $grid = wrapper.find('[role="application"]')
expect($grid.exists()).toBe(true)

let $cell = $grid.find('[data-date="2020-01-01"]')
expect($cell.exists()).toBe(true)
expect($cell.classes()).not.toContain('my-info')

$cell = $grid.find('[data-date="2020-01-02"]')
expect($cell.exists()).toBe(true)
expect($cell.classes()).toContain('my-info')

$cell = $grid.find('[data-date="2020-01-03"]')
expect($cell.exists()).toBe(true)
expect($cell.classes()).not.toContain('my-info')

wrapper.destroy()
})
})
154 changes: 79 additions & 75 deletions src/components/form-file/form-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,83 @@ const getAllFileEntriesInDirectory = (directoryReader, path = '') =>
readDirectoryEntries()
})

// --- Props ---

const props = makePropsConfigurable(
{
...formControlProps,
...formCustomProps,
...formStateProps,
...formSizeProps,
value: {
type: [File, Array],
default: null,
validator(value) {
/* istanbul ignore next */
if (value === '') {
warn(VALUE_EMPTY_DEPRECATED_MSG, NAME_FORM_FILE)
return true
}
return isUndefinedOrNull(value) || isValidValue(value)
}
},
accept: {
type: String,
default: ''
},
// Instruct input to capture from camera
capture: {
type: Boolean,
default: false
},
placeholder: {
type: String,
default: 'No file chosen'
},
browseText: {
type: String,
default: 'Browse'
},
dropPlaceholder: {
type: String,
default: 'Drop files here'
},
noDropPlaceholder: {
type: String,
default: 'Not allowed'
},
multiple: {
type: Boolean,
default: false
},
directory: {
type: Boolean,
default: false
},
// TODO:
// Should we deprecate this and only support flat file structures?
// Nested file structures are only supported when files are dropped
// A Chromium "bug" prevents `webkitEntries` from being populated
// on the file input's `change` event and is marked as "WontFix"
// Mozilla implemented the behavior the same way as Chromium
// See: https://bugs.chromium.org/p/chromium/issues/detail?id=138987
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1326031
noTraverse: {
type: Boolean,
default: false
},
noDrop: {
type: Boolean,
default: false
},
fileNameFormatter: {
type: Function
// default: null
}
},
NAME_FORM_FILE
)

// @vue/component
export const BFormFile = /*#__PURE__*/ Vue.extend({
name: NAME_FORM_FILE,
Expand All @@ -124,80 +201,7 @@ export const BFormFile = /*#__PURE__*/ Vue.extend({
prop: 'value',
event: 'input'
},
props: makePropsConfigurable(
{
...formControlProps,
...formCustomProps,
...formStateProps,
...formSizeProps,
value: {
type: [File, Array],
default: null,
validator(value) {
/* istanbul ignore next */
if (value === '') {
warn(VALUE_EMPTY_DEPRECATED_MSG, NAME_FORM_FILE)
return true
}
return isUndefinedOrNull(value) || isValidValue(value)
}
},
accept: {
type: String,
default: ''
},
// Instruct input to capture from camera
capture: {
type: Boolea 6D40 n,
default: false
},
placeholder: {
type: String,
default: 'No file chosen'
},
browseText: {
type: String,
default: 'Browse'
},
dropPlaceholder: {
type: String,
default: 'Drop files here'
},
noDropPlaceholder: {
type: String,
default: 'Not allowed'
},
multiple: {
type: Boolean,
default: false
},
directory: {
type: Boolean,
default: false
},
// TODO:
// Should we deprecate this and only support flat file structures?
// Nested file structures are only supported when files are dropped
// A Chromium "bug" prevents `webkitEntries` from being populated
// on the file input's `change` event and is marked as "WontFix"
// Mozilla implemented the behavior the same way as Chromium
// See: https://bugs.chromium.org/p/chromium/issues/detail?id=138987
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1326031
noTraverse: {
type: Boolean,
default: false
},
noDrop: {
type: Boolean,
default: false
},
fileNameFormatter: {
type: Function
// default: null
}
},
NAME_FORM_FILE
),
props,
data() {
return {
files: [],
Expand Down Expand Up @@ -269,7 +273,7 @@ export const BFormFile = /*#__PURE__*/ Vue.extend({
},
computedFileNameFormatter() {
const { fileNameFormatter } = this
return fileNameFormatter.name !== 'default'
return fileNameFormatter.name !== props.fileNameFormatter.default.name
? fileNameFormatter
: this.defaultFileNameFormatter
},
Expand Down
4 changes: 3 additions & 1 deletion src/components/form-spinbutton/form-spinbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ export const BFormSpinbutton = /*#__PURE__*/ Vue.extend({
},
computedFormatter() {
const { formatterFn } = this
return formatterFn.name !== 'default' ? formatterFn : this.defaultFormatter
return formatterFn.name !== props.formatterFn.default.name
? formatterFn
: this.defaultFormatter
},
computedAttrs() {
return {
Expand Down
Loading
0