Skip to content

Commit c432ff3

Browse files
authored
Fix @container queries inside selectors (#1533)
1 parent 5f66abb commit c432ff3

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

.changeset/soft-kiwis-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vanilla-extract/css': patch
3+
---
4+
5+
Fixes a bug where `@container` queries inside `selectors` were not being generated

packages/css/src/transformCss.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,50 @@ describe('transformCss', () => {
11661166
`);
11671167
});
11681168

1169+
it('should handle container queries inside selectors', () => {
1170+
expect(
1171+
transformCss({
1172+
composedClassLists: [],
1173+
localClassNames: ['testClass'],
1174+
cssObjs: [
1175+
{
1176+
type: 'local',
1177+
selector: 'testClass',
1178+
rule: {
1179+
containerName: 'myContainer',
1180+
'@container': {
1181+
'myContainer (min-width: 700px)': {
1182+
color: 'red',
1183+
},
1184+
},
1185+
selectors: {
1186+
['h1 &']: {
1187+
'@container': {
1188+
'myContainer (min-width: 700px)': {
1189+
color: 'blue',
1190+
},
1191+
},
1192+
},
1193+
},
1194+
},
1195+
},
1196+
],
1197+
}).join('\n'),
1198+
).toMatchInlineSnapshot(`
1199+
.testClass {
1200+
container-name: myContainer;
1201+
}
1202+
@container myContainer (min-width: 700px) {
1203+
.testClass {
1204+
color: red;
1205+
}
1206+
h1 .testClass {
1207+
color: blue;
1208+
}
1209+
}
1210+
`);
1211+
});
1212+
11691213
it('should handle @layer declarations', () => {
11701214
expect(
11711215
transformCss({

packages/css/src/transformCss.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,11 @@ class Stylesheet {
403403
conditions,
404404
);
405405
this.transformMedia(selectorRoot, selectorRule['@media'], conditions);
406+
this.transformContainer(
407+
selectorRoot,
408+
selectorRule['@container'],
409+
conditions,
410+
);
406411
});
407412
}
408413

0 commit comments

Comments
 (0)