mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
Bugfix: scoped styles (#178)
This commit is contained in:
parent
7b55d3d43e
commit
87ab4c6927
3 changed files with 13 additions and 5 deletions
5
.changeset/wicked-sloths-hide.md
Normal file
5
.changeset/wicked-sloths-hide.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Bugfix: Scoped CSS with pseudoclasses and direct children selectors
|
|
@ -75,18 +75,18 @@ export function scopeRule(selector: string, className: string) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// don‘t scope body, title, etc.
|
// don’t scope body, title, etc.
|
||||||
if (NEVER_SCOPED_TAGS.has(value)) {
|
if (CSS_SEPARATORS.has(value) || NEVER_SCOPED_TAGS.has(value)) {
|
||||||
ss = head + value + tail;
|
ss = head + value + tail;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// scope everything else
|
// scope everything else
|
||||||
let newSelector = ss.substring(start, end);
|
let newSelector = value;
|
||||||
const pseudoIndex = newSelector.indexOf(':');
|
const pseudoIndex = newSelector.indexOf(':');
|
||||||
if (pseudoIndex > 0) {
|
if (pseudoIndex > 0) {
|
||||||
// if there‘s a pseudoclass (:focus)
|
// if there’s a pseudoclass (:focus or ::before)
|
||||||
ss = head + newSelector.substring(start, pseudoIndex) + c + newSelector.substr(pseudoIndex) + tail;
|
ss = head + newSelector.substring(0, pseudoIndex) + c + newSelector.substr(pseudoIndex) + tail;
|
||||||
} else {
|
} else {
|
||||||
ss = head + newSelector + c + tail;
|
ss = head + newSelector + c + tail;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,9 @@ ScopedStyles('Scopes rules correctly', () => {
|
||||||
'.class~:global(a)': `.class.${className}~a`,
|
'.class~:global(a)': `.class.${className}~a`,
|
||||||
'.class *': `.class.${className} .${className}`,
|
'.class *': `.class.${className} .${className}`,
|
||||||
'.class>*': `.class.${className}>.${className}`,
|
'.class>*': `.class.${className}>.${className}`,
|
||||||
|
'.class button:focus': `.class.${className} button.${className}:focus`,
|
||||||
|
'.class h3::before': `.class.${className} h3.${className}::before`,
|
||||||
|
'button:focus::before': `button.${className}:focus::before`,
|
||||||
'.class :global(*)': `.class.${className} *`,
|
'.class :global(*)': `.class.${className} *`,
|
||||||
'.class :global(.nav:not(.is-active))': `.class.${className} .nav:not(.is-active)`, // preserve nested parens
|
'.class :global(.nav:not(.is-active))': `.class.${className} .nav:not(.is-active)`, // preserve nested parens
|
||||||
'.class :global(ul li)': `.class.${className} ul li`, // allow doubly-scoped selectors
|
'.class :global(ul li)': `.class.${className} ul li`, // allow doubly-scoped selectors
|
||||||
|
|
Loading…
Reference in a new issue