From 58232af948e8d5222e6ecf64aa8661d3d8baa867 Mon Sep 17 00:00:00 2001 From: Sam Moore Date: Fri, 20 Nov 2026 13:41:12 -0500 Subject: [PATCH] fix(compiler): compile one-value padding-block/-inline to paddingVertical/paddingHorizontal Android's Fabric TextInput applies its EditText theme padding (about 21dp) to every edge it finds no padding for, and it only checks padding, paddingVertical/paddingHorizontal and the single sides. React Native maps paddingBlock and paddingInline to the same Yoga edges as paddingVertical and paddingHorizontal, but that check doesn't see them. So a Tailwind py-*/px-* TextInput kept the theme padding. Renaming the keys at compile time fixes literal and var() values alike (propertyRename covers the unparsed path), costs nothing at runtime, and renders the same as before on every other component. Nativewind v4 rendered physical keys for py-*/px-*, so this fixes a v4 regression. Diagnosed in #400, which expanded the keys at runtime instead. Co-authored-by: Daewoon Kim Co-Authored-By: Claude Opus 5.5 --- src/__tests__/native/logical-padding.test.tsx | 23 +++++++++++++++++++ src/__tests__/vendor/tailwind/@apply.test.tsx | 4 ++-- .../vendor/tailwind/spacing.test.tsx | 4 ++-- src/compiler/declarations.ts | 9 ++++++-- 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 src/__tests__/native/logical-padding.test.tsx diff --git a/src/__tests__/native/logical-padding.test.tsx b/src/__tests__/native/logical-padding.test.tsx new file mode 100644 index 00000000..52e37837 --- /dev/null +++ b/src/__tests__/native/logical-padding.test.tsx @@ -0,0 +1,23 @@ +import { render, screen } from "@testing-library/react-native"; +import { TextInput } from "react-native-css/components/TextInput"; +import { registerCSS, testID } from "react-native-css/jest"; + +// Android's TextInput keeps its theme padding unless it sees padding, +// paddingVertical/paddingHorizontal or a physical side, so a one-value +// padding-block/padding-inline must not reach it as paddingBlock/paddingInline. +describe.each([ + ["folded", {}], + ["kept", { inlineVariables: false }], +] as const)("variables %s", (_, options) => { + test.each([ + ["padding-block: 8px", { paddingVertical: 8 }], + ["padding-inline: 16px", { paddingHorizontal: 16 }], + ["--s: 6px; padding-block: var(--s)", { paddingVertical: 6 }], + ["--s: 6px; padding-inline: calc(var(--s) * 2)", { paddingHorizontal: 12 }], + ["padding-block: 1px 2px", { paddingBlockStart: 1, paddingBlockEnd: 2 }], + ])("%s", (body, expected) => { + registerCSS(`.a { ${body} }`, options); + render(); + expect(screen.getByTestId(testID).props.style).toStrictEqual(expected); + }); +}); diff --git a/src/__tests__/vendor/tailwind/@apply.test.tsx b/src/__tests__/vendor/tailwind/@apply.test.tsx index 41b01f50..2a88f6d7 100644 --- a/src/__tests__/vendor/tailwind/@apply.test.tsx +++ b/src/__tests__/vendor/tailwind/@apply.test.tsx @@ -20,8 +20,8 @@ test("@apply", async () => { borderRadius: 7, color: "#fff", fontWeight: 600, - paddingBlock: 7, - paddingInline: 14, + paddingVertical: 7, + paddingHorizontal: 14, boxShadow: [ { offsetX: 0, diff --git a/src/__tests__/vendor/tailwind/spacing.test.tsx b/src/__tests__/vendor/tailwind/spacing.test.tsx index 520fcbc7..79b4fe80 100644 --- a/src/__tests__/vendor/tailwind/spacing.test.tsx +++ b/src/__tests__/vendor/tailwind/spacing.test.tsx @@ -8,12 +8,12 @@ describe("Spacing - Padding", () => { }); test("px-0", async () => { expect(await renderCurrentTest()).toStrictEqual({ - props: { style: { paddingInline: 0 } }, + props: { style: { paddingHorizontal: 0 } }, }); }); test("py-0", async () => { expect(await renderCurrentTest()).toStrictEqual({ - props: { style: { paddingBlock: 0 } }, + props: { style: { paddingVertical: 0 } }, }); }); test("pt-0", async () => { diff --git a/src/compiler/declarations.ts b/src/compiler/declarations.ts index 197a9c69..e5e5a8b9 100644 --- a/src/compiler/declarations.ts +++ b/src/compiler/declarations.ts @@ -72,6 +72,11 @@ const propertyRename: Record = { "border-block-start-width": "border-top-width", "border-block-end-width": "border-bottom-width", "font-variant-caps": "font-variant", + // React Native maps paddingBlock/paddingInline to the same Yoga edges as + // paddingVertical/paddingHorizontal, but Android's TextInput only sees the + // latter and otherwise keeps its theme padding + "padding-block": "padding-vertical", + "padding-inline": "padding-horizontal", }; // React Native only supports a uniform borderStyle, so per-side border @@ -702,7 +707,7 @@ function parsePaddingBlock( { value }: DeclarationType<"padding-block">, builder: StylesheetBuilder, ) { - builder.addShorthand("padding-block", { + builder.addShorthand("padding-vertical", { "padding-block-start": parseLengthPercentageOrAuto( value.blockStart, builder, @@ -715,7 +720,7 @@ function parsePaddingInline( { value }: DeclarationType<"padding-inline">, builder: StylesheetBuilder, ) { - builder.addShorthand("padding-inline", { + builder.addShorthand("padding-horizontal", { "padding-inline-start": parseLengthPercentageOrAuto( value.inlineStart, builder,