Skip to content

fix(props): consider prop types order for default bool value #7583

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

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 4 additions & 1 deletion src/core/util/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export function validateProp (
if (isType(Boolean, prop.type)) {
if (absent && !hasOwn(prop, 'default')) {
value = false
} else if (!isType(String, prop.type) && (value === '' || value === hyphenate(key))) {
} else if (
(!isType(String, prop.type) || prop.type.indexOf(String) > prop.type.indexOf(Boolean)) &&
(value === '' || value === hyphenate(key))
) {
value = true
}
}
Expand Down
17 changes: 17 additions & 0 deletions test/unit/features/component/component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,23 @@ describe('Component', () => {
expect(vm.$el.outerHTML).toBe('<ul><li>1</li><li>2</li></ul>')
})

it('must consider the order of props when using Boolean and String types', () => {
const vm = new Vue({
template: '<test ref="test" booleanOrString stringOrBoolean />',
components: {
test: {
template: '<div></div>',
props: {
booleanOrString: [Boolean, String],
stringOrBoolean: [String, Boolean]
}
}
}
}).$mount()
expect(vm.$refs.test.$props.booleanOrString).toBe(true)
expect(vm.$refs.test.$props.stringOrBoolean).toBe('')
})

it('should warn when using camelCased props in in-DOM template', () => {
new Vue({
data: {
Expand Down