question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty boolean prop not recognised

See original GitHub issue

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:

props: {
    required: { type: Boolean, default: false }
}

With this HTML code:

<component required></component>

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:

<component required="true"></component>

But this pattern actually generates an error in regular Vue (Invalid prop: type check failed), so it’s not really consistent or intuitive.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
karol-fcommented, Jul 5, 2018
0reactions
woubuccommented, Jun 25, 2018

My problem is that omitting a default value will make it default to undefined rather than false, so while it’s a falsy value (matching !prop) it won’t match prop === false. JSFiddle illustrating this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

When using [Boolean, String] props, Boolean does not work ...
Create a component property that has [Boolean, String] types. The HTML5-like attribute doesn't behave like a normal Boolean value anymore, ...
Read more >
Null boolean props if not given in Vue? - Stack Overflow
I read false on the console. I would like to get null if the property is not given and the boolean value elsewhere....
Read more >
Boolean() constructor - JavaScript - MDN Web Docs
The Boolean() constructor can create Boolean objects or return primitive values of type ... This property is legacy and non-standard and should not...
Read more >
A complete guide to React default props - LogRocket Blog
Cover three ways to implement default props in React and provide default values for props that are not required by the component.
Read more >
Problem with Boolean prop not reacting on watch sometimes
That's because you've obscured your source of truth. You should only ever rely on one source to determine the state. In your case...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found