Skip to content

Added support for CSS modules in hasClass #106

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
merged 5 commits into from
Oct 17, 2017
Merged

Added support for CSS modules in hasClass #106

merged 5 commits into from
Oct 17, 2017

Conversation

nblackburn
Copy link
Contributor

@nblackburn nblackburn commented Oct 16, 2017

Checks the className against $style where available.

  • Allows for checking classes that were converted with css modules without needing to know what it was converted to.
  • Only works when $style exists on the vm and a mapping is available for the target class.

DISCLAIMER: Not a fan of defining a function argument but it's the cleanest solution.

@nblackburn
Copy link
Contributor Author

nblackburn commented Oct 16, 2017

Made some tweaks so that the function variables are not getting redefined at the cost of consiceness, sorry 😢.

Copy link
Member

@eddyerburgh eddyerburgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a unit test please

@nblackburn
Copy link
Contributor Author

Sure, i was going to add one but didn't have time yesterday.

@nblackburn
Copy link
Contributor Author

Added a unit test

@eddyerburgh
Copy link
Member

The compatibility tests are failing, it looks like $style is implemented differently in Vue 2.0.x

To debug you can run the npm run test:compatibility

@nblackburn
Copy link
Contributor Author

Should be good to go now, sorry about that.

FYI: You can supress all of the stuff being spewed out on console in the karma runner with the client.captureConsole property.

Copy link
Member

@eddyerburgh eddyerburgh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test was correct, but the code needs to be changed.

Can you check how scoped classes are dealt with in Vue 2.0.x and add a fix?

You can see an example where we have different behavior depending on Vue version here - https://github.com/vuejs/vue-test-utils/blob/dev/src/wrappers/wrapper.js#L297.

@eddyerburgh
Copy link
Member

And can you revert the test to the previous test, where you had a class but had a scoped style block

@nblackburn
Copy link
Contributor Author

nblackburn commented Oct 17, 2017

@eddyerburgh I am not convinced the test was correct as to be able to use css modules, the class needs to be that of the mapped (found in $style) one rather than the original which to my understanding is not done automatically.

https://vue-loader.vuejs.org/en/features/css-modules.html

@eddyerburgh
Copy link
Member

eddyerburgh commented Oct 17, 2017

The test was correct, you can see the example in the vue loader docs —https://vue-loader.vuejs.org/en/features/scoped-css.html

@nblackburn
Copy link
Contributor Author

nblackburn commented Oct 17, 2017

@eddyerburgh this feature is for CSS modules, not scoped CSS. Hence the reference to css-modules in my last comment, the fact i am using $style and the test using the module directive instead of scoped.

@nblackburn nblackburn changed the title Added support for $style in hasClass Added support for CSS modules in hasClass Oct 17, 2017
@eddyerburgh
Copy link
Member

Ah sorry 👍

You're right then, the test you have now looks correct

@eddyerburgh eddyerburgh merged commit de89293 into vuejs:dev Oct 17, 2017
@nblackburn
Copy link
Contributor Author

Cool, thanks 👍

@nblackburn nblackburn deleted the feature/$style-support branch October 17, 2017 14:24
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

Successfully merging this pull request may close these issues.

2 participants