-
Notifications
You must be signed in to change notification settings - Fork 186
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
Empty boolean prop not recognised #128
Comments
Ok, thanks for the issue. I'll look at it. Regards. |
I have found that for Booleans all I need is the type without a default:
This will get you the desired result. By default it will not be present, and when adding a valueless attribute it will be true. |
This solution does not appear to work for me @dennisbaskin props: {
required: { type: Boolean },
} <component required></component> With this code, |
@woubuc here's a jsfiddle: https://jsfiddle.net/kaLe610e/7/. Maybe share how you are using it through another fiddle? |
Curious, it seems I wonder if this is different on purpose? Cause my understanding is that both versions should be functionally the same. Anyway, this does give me a solution, so thanks for your help @dennisbaskin! Although I think the inconsistent API should still be looked at further. |
The way I tend to look at it is that for Boolean properties I never need to set defaults. By default it’s either added or not. If it needs to be a negated property I name the attribute appropriately. For example For me following this pattern made the problem of not being consistent with Vue a non issue. |
My problem is that omitting a default value will make it default to |
Fixed in https://github.com/karol-f/vue-custom-element/releases/tag/v3.2.2, thanks for reporting! |
Hi! We've been using vue-custom-element the last couple of weeks on our new project and we love it! Custom elements are so much more flexible than regular Vue components, and not having to include the Vue runtime is so great.
Unfortunately I did find an inconsistency in how props are handled between Vue and vue-custom-element.
If I have the following prop:
With this HTML code:
In regular Vue, this code works as expected (
this.required
is true), but when doing the same on a custom element, the boolean remained false.The following is needed to make it work:
But this pattern actually generates an error in regular Vue (
Invalid prop: type check failed
), so it's not really consistent or intuitive.The text was updated successfully, but these errors were encountered: