Vue: <input :is="textarea"> broken

Created on 13 Aug 2017  ·  9Comments  ·  Source: vuejs/vue

Version

2.4.2

Reproduction link

https://jsfiddle.net/pi0/qnvcgujb

Steps to reproduce

This is working with 2.3 but not 2.4 anymore: (see provided fiddles)

<input v-model="value" is="textarea"/>

What is expected?

This was the behavior of 2.3.x:

https://jsfiddle.net/pi0/yL4rwesh

What is actually happening?

When using :is="textarea" to dynamically change input type to a text area neither :value or v-model are not working anymore. (There is also a common case for both which <component :is="..." is not working)


Using dynamic components is a common usage for component libraries like BootrapVue which user can dynamically change elements behavior. here is the current implementation we are falling back to v-if/v-else as a fix, But is it an intentional breaking change?

contribution welcome good first issue regression

Most helpful comment

Maybe we could check whether el.component is a real custome component before apply the genComponentModel method ? @posva

This could be a nice first contribution, I'll try to fix it over the weekend in case someone wants to have a try.

All 9 comments

Didn't @akryum wrote a similar issue (cannot rely find it on the phone)?

Nvmd, it was something different

⚠️ component + is + textarea/input + v-model wasn't working before either because v-model is different for components.

the input + is is now behaving as a component + is (instead of treating it as an input) which is why I marked this as a regression
I still haven't checked if we introduced that to fix something else 😅

Will #6344 fix this issue?

@mosinve, no, it doesn't.

Maybe we could check whether el.component is a real custome component before apply the genComponentModel method ? @posva

This could be a nice first contribution, I'll try to fix it over the weekend in case someone wants to have a try.

@defcc Agree on all the points!

@defcc The problem with that idea is el.component can be an expression with dynamic :is bindings, so we don't really know at compile time whether it is a component or not.

The original intention of is is really only meant for dynamic component switching, and in some cases allowing "upgrading" a normal element to a component (primarily for when using in-dom template + where HTML has element placement restrictions, e.g. trying to use a component inside <table>). So somehow I feel the current behavior sticks to that intention better...

Unfortunately, the fix by @cwang22 in #6453 will break cases where users are casting <input> into a custom component with is.

For specific cases like component libs, it's probably better to manually handle events instead of using v-model for finer-grained control.

@pi0 I looked at the latest bootstrap-vue code and it seems form-input and form-textarea are split into separate components, which I think is a better direction.

Thanks @yyx990803 for good explanation about :is directive :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bdedardel picture bdedardel  ·  3Comments

hiendv picture hiendv  ·  3Comments

julianxhokaxhiu picture julianxhokaxhiu  ·  3Comments

lmnsg picture lmnsg  ·  3Comments

aviggngyv picture aviggngyv  ·  3Comments