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

Incorrect CSS emitted for "&" parent selector #187

Open
green-coder opened this issue Nov 20, 2021 · 0 comments
Open

Incorrect CSS emitted for "&" parent selector #187

green-coder opened this issue Nov 20, 2021 · 0 comments

Comments

@green-coder
Copy link

As mentioned in green-coder/girouette#74 (comment), the problem is:

(garden/css [".space-x-2" [#garden.selectors.CSSSelector{:selector "& > * + *"} {:margin-left "0.5rem"}]])
=> ".space-x-2 & > * + * {\n  margin-left: 0.5rem;\n}"

The expected output was more like .space-x-2 > * + * {\n margin-left: 0.5rem;\n} (without the &)

This bug happens because "& > * + *" is not matched by parent-selector-re in

(def
^{:private true
:doc "Matches a single \"&\" or \"&\" follow by one or more
non-whitespace characters."}
parent-selector-re
#"^&(?:\S+)?$")
(defn- extract-reference
"Extract the selector portion of a parent selector reference."
[selector]
(when-let [reference (->> (last selector)
(util/to-str)
(re-find parent-selector-re))]
(apply str (rest reference))))

This workaround is working:

(garden/css [".space-x-2" [#garden.selectors.CSSSelector{:selector "&>*+*"} {:margin-left "0.5rem"}]])
=> ".space-x-2>*+* {\n  margin-left: 0.5rem;\n}"
Vynlar added a commit to Vynlar/girouette that referenced this issue Nov 21, 2021
Garden's `&` selector does not behave as expected and this is a
hacky way around the problem.

In garden, the & symbol is used to target the parent element; however,
it does not work for the following selector:
`& * + *`. See: noprompt/garden#187

By removing all the spaces in the selector: `&>*+*`, it does work which
is what this commit changes.
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

1 participant