Support escaped characters in selectors
See original GitHub issueEdit from maintainers: this issue was repurposed, see https://github.com/airbnb/enzyme/issues/1218#issuecomment-334489966
Settings
- React v16
- Enzyme v3
When i have a component which has a className prop with special character /
or @
, it doesnt select anything. I feel enzyme breaks and doesn’t continue with the lines after this selector.
Example
const sampleComponent = () => (
<div className="u-width-1/2@small">
Something here
</div>
);
If I have the above component and if I want to select the div containing u-width-1/2@small
I tried
const component = shallow(<sampleComponent />);
component.find('.u-width-1/2@small') // This line seems to fail due to error in selector
/* Anything after this doesnt execute */
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (5 by maintainers)
Top Results From Across the Web
CSS.escape() - Web APIs - MDN Web Docs
The CSS.escape() static method returns a string containing the escaped string passed as parameter, mostly for use as part of a CSS selector....
Read more >CSS character escape sequences - Mathias Bynens
Here's a simple list of rules you should keep in mind when escaping a character in CSS. Keep in mind that if you're...
Read more >Escaping characters in CSS class selectors - Stack Overflow
I'm trying to implement this W3 description of character escapes in CSS class selectors. I'm running into problems with the abc\20 def ...
Read more >Using character escapes in markup and CSS - W3C
Using escapes with CSS identifiers ... Identifiers in CSS, such as class names in CSS selectors, can begin with - _ a-z or...
Read more >Using special characters in selectors - ProcessWire
This might be a silly question but wire('sanitizer')->selectorValue() seems to remove characters like ^ and = rather than escape them.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That’s not a valid class name - that won’t work in the browser either.
I agree with @yash0087 and @coderas, a class with an
@
symbol (or anything other than whitespace for that matter) is indeed a valid class name.It’s worth noting the class names are defined by the HTML spec rather than CSS – though the CSS spec defines what is a valid class selector as per @yash0087’s link above. The HTML5 spec clearly states that classes are simply “a set of space-separated tokens”, which have no restrictions other than whitespace characters: https://www.w3.org/TR/2011/WD-html5-20110525/elements.html#classes
In addition, the argument that
document.querySelector
does not allow those characters is also false.document.querySelector
uses the Selectors API, which explicitly states that the same escaping rules as CSS should be applied for special characters: https://drafts.csswg.org/selectors-4/#case-sensitive.