Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Use :is to make important selector option insensitive to DOM order
  • Loading branch information
adamwathan authored and RobinMalfait committed Mar 21, 2023
commit b10c7c186ab22a83f0098c380bda225153dfa36f
4 changes: 2 additions & 2 deletions src/lib/expandApplyAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,14 +548,14 @@ function processApply(root, context, localCache) {

let parentSelector =
isGenerated && importantSelector && parent.selector.indexOf(importantSelector) === 0
? parent.selector.slice(importantSelector.length)
? parent.selector.slice(importantSelector.length + 5 /* ' is:('.length */, -1)
: parent.selector

rule.selector = replaceSelector(parentSelector, rule.selector, applyCandidate)

// And then re-add it if it was removed
if (importantSelector && parentSelector !== parent.selector) {
rule.selector = `${importantSelector} ${rule.selector}`
rule.selector = `${importantSelector} :is(${rule.selector})`
}

rule.walkDecls((d) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/generateRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ function getImportantStrategy(important) {
}

rule.selectors = rule.selectors.map((selector) => {
return `${important} ${selector}`
return `${important} :is(${selector})`
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/apply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2120,10 +2120,10 @@ crosscheck(({ stable, oxide }) => {
let result = await run(input, config)

expect(result.css).toMatchFormattedCss(css`
#myselector .custom-utility {
#myselector :is(.custom-utility) {
font-weight: 400;
}
#myselector .group:hover .custom-utility {
#myselector :is(.group:hover .custom-utility) {
text-decoration-line: underline;
}
`)
Expand Down
6 changes: 3 additions & 3 deletions tests/experimental.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ crosscheck(() => {
--tw-shadow: 0 0 #0000;
--tw-shadow-colored: 0 0 #0000;
}
#app .resize {
#app :is(.resize) {
resize: both;
}
#app .divide-y > :not([hidden]) ~ :not([hidden]) {
#app :is(.divide-y > :not([hidden]) ~ :not([hidden])) {
--tw-divide-y-reverse: 0;
border-top-width: calc(1px * calc(1 - var(--tw-divide-y-reverse)));
border-bottom-width: calc(1px * var(--tw-divide-y-reverse));
}
#app .shadow {
#app :is(.shadow) {
--tw-shadow: 0 1px 3px 0 #0000001a, 0 1px 2px -1px #0000001a;
--tw-shadow-colored: 0 1px 3px 0 var(--tw-shadow-color),
0 1px 2px -1px var(--tw-shadow-color);
Expand Down
14 changes: 7 additions & 7 deletions tests/important-selector.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,31 +122,31 @@ crosscheck(() => {
transform: rotate(360deg);
}
}
#app .animate-spin {
#app :is(.animate-spin) {
animation: 1s linear infinite spin;
}
#app .font-bold {
#app :is(.font-bold) {
font-weight: 700;
}
.custom-util {
button: no;
}
#app .group:hover .group-hover\:focus-within\:text-left:focus-within {
#app :is(.group:hover .group-hover\:focus-within\:text-left:focus-within) {
text-align: left;
}
#app :is([dir='rtl'] .rtl\:active\:text-center:active) {
#app :is(:is([dir='rtl'] .rtl\:active\:text-center:active)) {
text-align: center;
}
@media (prefers-reduced-motion: no-preference) {
#app .motion-safe\:hover\:text-center:hover {
#app :is(.motion-safe\:hover\:text-center:hover) {
text-align: center;
}
}
#app :is(.dark .dark\:focus\:text-left:focus) {
#app :is(:is(.dark .dark\:focus\:text-left:focus)) {
text-align: left;
}
@media (min-width: 768px) {
#app .md\:hover\:text-right:hover {
#app :is(.md\:hover\:text-right:hover) {
text-align: right;
}
}
Expand Down