Skip to content

Commit 8641738

Browse files
authored
Sprinkles: Fix handling of zero values in shorthands (#432)
1 parent 8224343 commit 8641738

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

.changeset/chilled-goats-hunt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vanilla-extract/sprinkles': patch
3+
---
4+
5+
Fix handling of zero values in shorthands

packages/sprinkles/src/createSprinkles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ export const createSprinkles =
8585

8686
for (const shorthand of shorthandNames) {
8787
const value = props[shorthand];
88-
if (value) {
88+
if (value != null) {
8989
const sprinkle = sprinklesStyles[shorthand];
9090
hasShorthands = true;
9191
for (const propMapping of sprinkle.mappings) {
9292
shorthands[propMapping] = value;
93-
if (!nonShorthands[propMapping]) {
93+
if (nonShorthands[propMapping] == null) {
9494
delete nonShorthands[propMapping];
9595
}
9696
}

tests/sprinkles/index.css.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,15 @@ export const propertiesWithPaddingShorthands = defineProperties({
114114
paddingY: ['paddingTop', 'paddingBottom'],
115115
},
116116
});
117+
118+
export const shorthandsWithZeroValues = defineProperties({
119+
properties: {
120+
marginTop: {
121+
0: '0rem',
122+
1: '0.5rem',
123+
},
124+
},
125+
shorthands: {
126+
mt: ['marginTop'],
127+
},
128+
});

tests/sprinkles/sprinkles.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
conditionalPropertiesWithMultipleDefaultConditions,
1313
conditionalPropertiesWithoutDefaultCondition,
1414
conditionalPropertiesWithoutResponsiveArray,
15+
shorthandsWithZeroValues,
1516
} from './index.css';
1617

1718
describe('sprinkles', () => {
@@ -264,6 +265,16 @@ describe('sprinkles', () => {
264265
);
265266
});
266267

268+
it('should handle shorthands with zero values', () => {
269+
const sprinkles = createSprinkles(shorthandsWithZeroValues);
270+
271+
expect(
272+
sprinkles({
273+
mt: 0,
274+
}),
275+
).toMatchInlineSnapshot(`"sprinkles_marginTop_0__1kw4bre2a"`);
276+
});
277+
267278
it('should preserve config order of shorthands', () => {
268279
const sprinkles = createSprinkles(propertiesWithPaddingShorthands);
269280

0 commit comments

Comments
 (0)