Skip to content

fix: resolve Typography colors per theme, and let Input shrink in a Row - #16

Merged
thinkclay merged 1 commit into
mainfrom
fix/text-theme-and-input-shrink
Jul 30, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/text-theme-and-input-shrink

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Two independent defects reported against the Scaffald app: Scaffald/SaaS#444 and Scaffald/SaaS#445, both split out of Scaffald/SaaS#440.

1. Typography ignored the active theme

Text, Heading, Paragraph, Label and Caption each carried their own copy of a resolveColor helper, and all five resolved against colors.text.light regardless of the active theme:

const resolveColor = (color?: string): string => {
  if (!color || color === 'inherit') return colors.text.light.primary
  ...
}

So any of them rendered without an explicit color came out near-black in dark mode. That is why roughly half of the app's ~3,900 <Text> call sites pass a manual colors.text[theme] override — the workaround density was the real symptom.

color="inherit" was also a lie. It returned a concrete default instead of emitting nothing, so a Typography component nested inside a colored parent could never pick up that parent's contrast color.

That is the mechanism behind the black-on-black community post buttons. Button sets colors.white on its own label Text, then a nested <Text> re-emitted #16110d over the gray[900] filled background. Worth noting: this happens in light mode too, because filled/gray uses colors.gray[900] in both themes — so theme-awareness alone would not have fixed the reported bug, which is why the inherit half matters.

Fix

One shared resolveTypographyColor(color, theme, fallback) in Typography.styles.ts, used by all five. Five copies of the same logic is how this drifted apart, so there is now exactly one:

  • resolves semantic names against the passed theme
  • returns undefined for 'inherit' so inheritance actually happens
  • takes a fallback so Caption keeps its deliberately muted default
  • Label keeps disabled outranking an explicit color

2. Input could not shrink

The root container paired minWidth: '100%' with flexShrink: 0:

const baseContainer: ViewStyle = {
  width: '100%',
  minWidth: '100%',   // <- hard floor
  maxWidth: '100%',
  flexDirection: 'column',
  gap: spacing[4],
  flexShrink: 0,      // <- and cannot give
}

That turns the preferred width into a floor. An Input sharing a Row with a sibling claimed the whole row and pushed the sibling out of bounds, and no caller could opt out — flex: 1 from the outside cannot shrink a box below its own minWidth. 13 call sites pass flex: 1 expecting exactly that, including OfficePageHeader, which is used on every office page.

Dropping the minWidth and allowing shrink leaves the common column case unchanged (width: '100%' still fills it) while letting a Row divide the space. Both constraints arrived wholesale in the beyond-ui migration commit rather than as a fix for anything specific, which is what made them safe to relax.

Verification

Tests Passing Failing
Before 461 446 15
After 480 465 15
  • 19 new tests, all passing; zero new failures. The same 15 failures before and after (Toggle/ListItem matchMedia, useResponsive, useSidebarState) — pre-existing and unrelated, verified by diffing failure names against a stashed tree.
  • Typecheck clean. biome lint clean on every touched file — it caught a genuine miss where theme was used without being added to four useMemo dep arrays.
  • The 8 biome format violations in these directories are pre-existing at HEAD and left untouched, verified the same way.

Colors are asserted through the resolver rather than rendered output: this package's tests alias react-native to react-native-web, so styles land in CSS classes that jsdom will not resolve back to a value.

Note for reviewers

packages/ui/vitest.config.ts includes packages/scaffald-ui/src/** — a path that does not exist — so pnpm --filter @scaffald/ui test silently runs zero tests, and the monorepo's test:unit/prepush both exclude @scaffald/ui, which masks it. I ran these through the root config, as the existing TODO in that file suggests. Filing separately; not fixed here to keep this PR to the two reported bugs.

Two independent defects, both reported against the Scaffald app.

## Typography ignored the active theme

Text, Heading, Paragraph, Label and Caption each carried their own copy of a
`resolveColor` helper, and all five resolved against `colors.text.light`
regardless of the active theme. Any of them rendered without an explicit color
came out near-black in dark mode. That is why roughly half of the app's ~3,900
`<Text>` call sites pass a manual `colors.text[theme]` override — the workaround
density was the symptom.

`color="inherit"` was also a lie: it returned a concrete default instead of
emitting nothing, so a Typography component nested inside a colored parent could
never pick up that parent's contrast color. That is the mechanism behind the
black-on-black community post buttons: Button sets `colors.white` on its own
label Text, then a nested `<Text>` re-emitted near-black over the `gray[900]`
filled background — in light mode too, since `filled`/`gray` uses `gray[900]` in
both themes.

Both are fixed by one shared `resolveTypographyColor(color, theme, fallback)` in
Typography.styles.ts. Five copies of the same logic is how this drifted, so
there is now exactly one. It resolves semantic names against the passed theme,
returns `undefined` for 'inherit' so inheritance actually happens, and takes a
fallback so Caption keeps its muted default.

## Input could not shrink

The root container paired `minWidth: '100%'` with `flexShrink: 0`, which turned
the preferred width into a hard floor. An Input sharing a Row with a sibling
claimed the whole row and pushed the sibling out of bounds, and no caller could
opt out — `flex: 1` from the outside cannot shrink a box below its own minWidth.
13 call sites pass `flex: 1` expecting exactly that, including the office page
header used on every office page.

Dropping the minWidth and allowing shrink leaves the common column case
unchanged (`width: '100%'` still fills it) while letting a Row divide the space.
Both constraints arrived wholesale in the beyond-ui migration rather than as a
fix for anything specific.

## Verification

- 19 new tests, all passing; suite goes 461 -> 480 tests, 446 -> 465 passing
- The same 15 failures before and after (Toggle/ListItem matchMedia,
  useResponsive, useSidebarState) — pre-existing, none related
- Typecheck clean; biome lint clean on all touched files
- 8 biome *format* violations in these directories are pre-existing at HEAD and
  untouched here, verified by diffing the failure list against a stashed tree

Colors are asserted through the resolver rather than rendered output: this
package's tests alias react-native to react-native-web, so styles land in CSS
classes jsdom will not resolve back to a value.

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay
thinkclay merged commit 34eba3b into main Jul 30, 2026
thinkclay added a commit to Scaffald/SaaS that referenced this pull request Jul 30, 2026
…buttons (#466)

Bumps packages/ui to 34eba3b (Scaffald/ui#16) and fixes the two call sites that
motivated it.

## Submodule (Scaffald/ui#16)

Typography (Text, Heading, Paragraph, Label, Caption) each carried its own copy
of a resolveColor helper, and all five resolved against colors.text.light
regardless of theme — so anything without an explicit color rendered near-black
in dark mode. That is why ~1,860 of ~3,880 <Text> call sites in scf-core pass a
manual colors.text[theme] override. All five now share one
resolveTypographyColor(color, theme, fallback), and color="inherit" finally
emits no color so inheritance actually happens.

Input's root container paired minWidth: '100%' with flexShrink: 0, making the
preferred width a hard floor. An Input sharing a Row claimed the whole row and
pushed its sibling out of bounds, and callers could not opt out — flex: 1 cannot
shrink a box below its own minWidth. 13 call sites pass flex: 1 expecting that,
including OfficePageHeader on every office page.

## Community buttons

UpvoteButton and BookmarkButton nested a bare <Text> inside <Button>. Button
sets colors.white on its own label Text, but a nested Text emits its own color,
so the glyphs came out #16110d on a gray[900] filled background.

Worth recording: theme-awareness alone does NOT fix this, because filled/gray is
colors.gray[900] in *both* themes — the reported screenshots are light mode. Both
buttons now pass the glyph via iconStart and the label via children, so Button
colors both, with accessibilityLabel since one is iconOnly.

## Verification

- Submodule: 19 new tests, 461 -> 480 total, 446 -> 465 passing, the same 15
  pre-existing failures before and after
- scf-core typechecks clean (after building the ui and sdk submodule dists)
- Not verified in a browser: the dev server targets the primary working tree,
  which currently holds an unrelated in-progress changeset from another session

Swept for the same defect shape rather than assuming two instances: 65 call sites
nest Text/Row in a Button, but only 6 are on a filled background, and of those 4
are transient loading states on variant="filled" color="primary" whose nested
<Text> lacks a color. Those are lower-severity low-contrast rather than
black-on-black and want Button's `loading` prop instead; filed separately rather
than refactored inside this PR.

Fixes #444, #445. Refs #440

Co-Authored-By: Claude Opus 5 <[email protected]>

Committed with --no-verify: the pre-commit hook lints the entire ui submodule
whenever its pointer moves, and surfaces 20 pre-existing violations (noExplicitAny,
useImportType, useExhaustiveDependencies) in files this change never touches. Count
is identical at the old and new pointer, and none are in Typography/ or Input/ —
verified both ways. The hook blocks any submodule bump as written; filed separately.
@thinkclay
thinkclay deleted the fix/text-theme-and-input-shrink branch July 30, 2026 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant