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

CSS Attribute selector should support |= and ~= #620

Closed
mohsen1 opened this issue Oct 1, 2016 · 9 comments
Closed

CSS Attribute selector should support |= and ~= #620

mohsen1 opened this issue Oct 1, 2016 · 9 comments

Comments

@mohsen1
Copy link

mohsen1 commented Oct 1, 2016

According to W3C spec an attribute selector can have |= adn ~= for matching value of the attribute.

Example: '[class|="someClass"]'

Why this is important and useful
CSS modules can append random strings at the end of css classes to "mangle" them. In test, we want to test for existence of classes without knowing the mangled class. Above example class can be someClass---AbCd123.

@blainekasten
Copy link
Contributor

This is definitely something we would love to support. There is currently a lot of work happening to refactor how we parse CSS and nodes internally. This will be a roadmap item but may take a bit to get to.

I work in the same world with mangled class names. They way I handle it is by having it my build system not mangle at all within the tests. You could try and refactor your build system in that way for now. Or you could import the CSS files and reference them the same way you assign the className values

@mohsen1
Copy link
Author

mohsen1 commented Oct 4, 2016

Yes, that's what we did eventually. We got rid of mangling in test.

Have you thought about using a CSS selector engine like Sizzle instead of writing your own?

@stephanschubert
Copy link

I just left almost the same comment here #595 (comment)

@davidcai
Copy link

davidcai commented Sep 7, 2017

Here is another example of requiring ~= support:

<div data-test="item"></div>
<div data-test="item item-active"></div>
<div data-test="item item-promoted"></div>
...

And we'd like to use selectors such as [data-test~="item-active"] to find all active items, and selector [data-test~="item"] to find all items.

@ljharb
Copy link
Member

ljharb commented Sep 26, 2017

I believe this is covered by v3; @aweary, can you confirm?

@aweary
Copy link
Collaborator

aweary commented Sep 26, 2017

@ljharb the infrastructure is there, but this still needs to be implemented. I'll be sending a PR for this today.

@hboylan
Copy link

hboylan commented Nov 8, 2017

Enzyme support for this would be awesome. I'm currently using Material UI, which mangles classes everywhere.

For mangled classes, most people would be interested in:

  • div[class^="something"] - starts with
  • div[class$="something"] - ends with
  • div[class*="something"] - contains

Here's the full reference from W3.

@aweary
Copy link
Collaborator

aweary commented Nov 8, 2017

There's an open PR for this: #1157

@ljharb
Copy link
Member

ljharb commented Jul 6, 2018

Added in #1157.

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

No branches or pull requests

7 participants