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

Double class getting binded #1806

Closed
miljan-aleksic opened this issue Nov 14, 2015 · 6 comments
Closed

Double class getting binded #1806

miljan-aleksic opened this issue Nov 14, 2015 · 6 comments

Comments

@miljan-aleksic
Copy link

When a class is set in an dom element which is being initied with Vue and the same class is set in the component root dom element, the final result is a double class. You can see the results here, check with the console the dom and you should see "compClass compClass" instead of just one.

It's not a big deal but doesn't seem the expected behaviour.

@posva
Copy link
Member

posva commented Nov 14, 2015

I don't think this is a bug... You can add your own classes to the component this way which is quite useful

@miljan-aleksic
Copy link
Author

I'm not referencing the feature, which is totally fine. What is wrong is that your final component will end up with two identical class names, as can be seen in the fiddle.

You would never write your code as <div class"myClass myClass"> right? Vue shouldn't neither.

@posva
Copy link
Member

posva commented Nov 14, 2015

I see but you're the one writing myClass twice. The user is free to add any class multiple times.
It's like you are waiting for vue to fix your mistakes.

@miljan-aleksic
Copy link
Author

Despite the reasons behind the repeated class, Vue could be merging instead of appending the classes. The same way when using jQuery.addClass() you expect the library to add the class only if doesn't already exists. You don't expect it to fix your mistakes, but to help you keep your code clean.

@posva
Copy link
Member

posva commented Nov 14, 2015

It could be a feature yet the example you gave is clearly a developer mistake, do you have a real use case? The jQuery example you're providing doesn't relate to this because we are talking about adding a class to a component that already holds that class

@miljan-aleksic
Copy link
Author

In my application I'm using the same class to locate the dom and init Vue on it as to style it after. My initial dom would be <div class="my-component-name"></div> and to make it sure it stays that way once Vue has replaced the content I keep the same class again in the component template declaration. Yes, it's on purpose and I could change that only to end up duplicating classes names. You could still argument that I could remove it from the component, but then my component would be prompt to style issues if for any reason I decide to change the initial dom class.

Again, I don't think its a big deal, its just not what I would expect from a class merging feature.

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