Skip to content
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

Merged class attributes are not preserved when a component is created from a render function and the root node has a class binding #8187

Closed
rodrigopedra opened this issue May 15, 2018 · 4 comments

Comments

@rodrigopedra
Copy link

rodrigopedra commented May 15, 2018

Version

2.5.16

Reproduction link

https://jsfiddle.net/jmabj70u/

updated: added child-compoent directly to compare expected vs actual results

https://jsfiddle.net/jmabj70u/1/

Steps to reproduce

  1. Create a component that render its content through a render function and render a child component with a static class attribute
  2. In the child component, add a class binding to the root element
  3. When the class binding is applied (for example, when a condition becomes true) the static classes passed from the parent component render function is lost

What is expected?

That the child component keeps both the static and dynamic classes

What is actually happening?

Only the dynamic classes added through the v-bind:class are kept in the root element


I looked through other issues reporting similar behaviors, the one more likely to be related is issue #1014 , but this one differs from that case since any of the components here are functional components.

updated: actual issue is vuejs/vue-loader#1014 (comment) see comment below

The example in the fiddle is a simplified version to showcase the problem. In my use-case, the parent component can render a different child component depending on a prop or state, the parent acts as a "proxy" or "polymorphic" component for several different children.

@rodrigopedra
Copy link
Author

An update, the issue I mentioned is #1014 but from vue-loader, pelase see the link below

vuejs/vue-loader#1014 (comment)

Sorry for the lack of attention

@posva
Copy link
Member

posva commented May 15, 2018

That is no longer the case though, it is now documented (https://vuejs.org/v2/guide/render-function.html#Passing-Attributes-and-Events-to-Child-Elements-Components). But that's for functional components

In your case you should either use class or staticClass, not attrs:

   return createElement( 'child-component', {
         class: {
         	big: true
         }
     }, this.$slots.default );

More at https://vuejs.org/v2/guide/render-function.html#The-Data-Object-In-Depth

@posva posva closed this as completed May 15, 2018
@rodrigopedra
Copy link
Author

Hi @posva , thanks for the feedback.

I couldn't find in any part of the guide or the API any reference of the staticClass usage.

Do you want me to make a PR adding this info on the guide?

@posva
Copy link
Member

posva commented May 15, 2018

Thank you but let's keep it how it is, I'm not sure if it was more of an internal property, people should use the class one instead 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants