question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS style selectors with multiple classes are not parsed correctly.

See original GitHub issue

Environment info

  • Cytoscape.js version : 3.21.0
  • Browser/Node.js & version : Chrome/14.19.0

Current (buggy) behaviour

When specifying a style selector such as node.class1.class2 { ... } in a css file, cytoscape fails to parse the selector correctly. It actually parses the selector as [‘node’, ‘class1.class2’] instead of [‘node’, ‘class1’, ‘class2’]. This appears to be caused by an incorrect regular expression ^\\.((?:[\\w-.]|(?:\\\\[\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\]\\^\\`\\{\\|\\}\\~]))+) being used to match the class. The correct expression is ^\\.((?:[\\w-]|(?:\\\\[\\!\\\"\\#\\$\\%\\&\\'\\(\\)\\*\\+\\,\\.\\/\\:\\;\\<\\=\\>\\?\\@\\[\\]\\^\\`\\{\\|\\}\\~]))+) (i.e. without the . after the [\\w- part.

Desired behaviour Ability to specify more than one selector class in the css (e.g. node.class1.class2).

Minimum steps to reproduce Create a style sheet file called my-style.css that defines a style with more than one class as a selector:

node.class1.class2 {
  background-fill: solid;
  background-color: #268dae;
}

Create a cytoscape graph that specifies the style: require('./my-style.css') property in the config (e.g. var myGraph = cytoscape({ ..., style: require('./my-style.css'), ... }).

Observe that the consumeExpr function in src/selector/parse.js fails to correctly parse the .class1.class2 as two separate classes. Instead in parses it as a single class and therefore fails to match the style properly when the match[Type.CLASS] function (in src/selector/query-type-match.js is invoked. The class passed into the match[Type.CLASS] function is .class1.class2 and therefore never matches anything since the node.classes property is an array with each class as a separate element.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
mkelly1495commented, Mar 20, 2022

I added a test that verifies correct behavior when an element has a period in the id name and updated the other tests where necessary.

0reactions
maxkfranzcommented, Apr 5, 2022

Your PR and issue are being used as an example to help onboard new contributors to Cytoscape.js. It will be merged in and released once that onboarding has completed – hopefully some time this week.

Thank you for your patience

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple Class / ID and Class Selectors - CSS-Tricks
Double Class Selector​​ Target an element that has all of multiple class es. Shown below with two class es, but not limited to...
Read more >
CSS selector for element with two classes not working
I am trying to style these elements, and the element with two classes can't be style different than the one with one class....
Read more >
CSS selectors - CSS: Cascading Style Sheets - MDN Web Docs
Class selector. Selects all elements that have the given class attribute. Syntax: .classname. Example: .index will match any element that ...
Read more >
Selectors - W3C
A simple selector is either a type selector or universal selector followed immediately by zero or more attribute selectors, ID selectors, or pseudo-classes, ......
Read more >
CSS .class Selector - W3Schools
To select elements with a specific class, write a period (.) character, followed by the name of the class. You can also specify...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found