close
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ export const parseIntermediateOrInvalidValue = (
if ("unit" in styleValue && styleValue.unit === "number") {
const numericValue = Number(value);
if (!Number.isNaN(numericValue) && !Number.isInteger(numericValue)) {
value = String(Math.round(numericValue));
// Only round if the decimal value is not valid for this property
// (e.g. z-index requires integers, but line-height accepts decimals)
const decimalTest = parseCssValue(property, value);
if (decimalTest.type === "invalid") {
value = String(Math.round(numericValue));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,48 @@ describe("Value ending with `-` should be considered unitless", () => {
});
});

test("Decimal number intermediate for line-height is not rounded", () => {
const result = parseIntermediateOrInvalidValue("line-height", {
type: "intermediate",
value: "1.5",
unit: "number",
});

expect(result).toEqual({
type: "unit",
value: 1.5,
unit: "number",
});
});

test("Decimal number intermediate for z-index is rounded to integer", () => {
const result = parseIntermediateOrInvalidValue("z-index", {
type: "intermediate",
value: "1.5",
unit: "number",
});

expect(result).toEqual({
type: "unit",
value: 2,
unit: "number",
});
});

test("Decimal number intermediate for column-count is rounded to integer", () => {
const result = parseIntermediateOrInvalidValue("column-count", {
type: "intermediate",
value: "2.7",
unit: "number",
});

expect(result).toEqual({
type: "unit",
value: 3,
unit: "number",
});
});

test("Unitless expression transformed to unitless", () => {
const result = parseIntermediateOrInvalidValue("line-height", {
type: "intermediate",
Expand Down
Loading