Skip to content

Boolean props without a value are not defaulted to true when there is a v-bind applied if they begin with on #7871

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

Open
d-ryabtsev opened this issue Mar 9, 2023 · 6 comments · May be fixed by #7872 or #8185
Labels
🐞 bug Something isn't working 🔩 p2-edge-case

Comments

@d-ryabtsev
Copy link

Vue version

3.2.47

Link to minimal reproduction

https://codesandbox.io/s/infallible-hofstadter-eetgd6?file=/src/components/HelloWorld.vue

Steps to reproduce

<template>
  <div>
    <div>{{ something }}</div>
    <div>{{ onSomething }}</div>
  </div>
</template>

<script>
export default {
  name: "HelloWorld",
  props: {
    onSomething: Boolean,
    something: Boolean,
  },
};
</script>
<template>
  <HelloWorld v-bind="{}" something on-something />
</template>

What is expected?

onSomething prop should default to true

What is actually happening?

The prop is ignored.

System Info

No response

Any additional comments?

No response

@d-ryabtsev d-ryabtsev changed the title Boolean props without a value are not defaulted to true when there is a v-bind applied Boolean props without a value are not defaulted to true when there is a v-bind applied if they begin with on Mar 9, 2023
@edison1105
Copy link
Member

The prefix 'on' is considered an event. It is not recommended to use the 'on' prefix as a boolean attribute.

@edison1105 edison1105 added 🐞 bug Something isn't working 🔩 p2-edge-case labels Mar 10, 2023
@d-ryabtsev
Copy link
Author

The prefix 'on' is considered an event. It is not recommended to use the 'on' prefix as a boolean attribute.

I appreciate that but this is not obvious from the docs and it is something that is difficult to change in large applications when moving from Vue 2 to Vue 3.

@KaygNas
Copy link

KaygNas commented Apr 28, 2023

The prefix 'on' is considered an event. It is not recommended to use the 'on' prefix as a boolean attribute.

Maybe some warning print on console would be better? Developer could be hinted by the warning and realize where the problem are when they stuck into this situation.

@LinusBorg
Copy link
Member

LinusBorg commented Apr 28, 2023

The prefix 'on' is considered an event. It is not recommended to use the 'on' prefix as a boolean attribute.

I appreciate that but this is not obvious from the docs and it is something that is difficult to change in large applications when moving from Vue 2 to Vue 3.

You're right in that docs would profit from an update in that regard. The general behavior is considered public API though and won't be changed in 3.x.

The prefix 'on' is considered an event. It is not recommended to use the 'on' prefix as a boolean attribute.

Maybe some warning print on console would be better? Developer could be hinted by the warning and realize where the problem are when they stuck into this situation.

Hard to do right considering it's technically fine to pass an event listener as a prop prefixed with on[A-Z], and we will already have lots of projects actually doing that in places like object v-bind

@d-ryabtsev
Copy link
Author

The prefix 'on' is considered an event. It is not recommended to use the 'on' prefix as a boolean attribute.

I appreciate that but this is not obvious from the docs and it is something that is difficult to change in large applications when moving from Vue 2 to Vue 3.

You're right in that docs would profit from an update in that regard. The general behavior is considered public API though and won't be changed in 3.x.

The prefix 'on' is considered an event. It is not recommended to use the 'on' prefix as a boolean attribute.

Maybe some warning print on console would be better? Developer could be hinted by the warning and realize where the problem are when they stuck into this situation.

Hard to do right considering it's technically fine to pass an event listener as a prop prefixed with on[A-Z], and we will already have lots of projects actually doing that in places like object v-bind

Are you saying that this won't be fixed?

@dschrul
Copy link

dschrul commented Sep 19, 2023

We also ran into this issue when upgrading from vue2 and it was really hard to figure it out. Is it documented anywhere that prop names beginning with "on" are problematic? A warning in the console would have been great.

edison1105 added a commit to KaygNas/core that referenced this issue Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working 🔩 p2-edge-case
Projects
None yet
5 participants