Skip to content

Use .blue() instead of .b() in textColorForBackgroundColor - #1031

Merged
9larsons merged 2 commits into
TryGhost:mainfrom
thomasjlee:always-blue
Aug 10, 2026
Merged

Use .blue() instead of .b() in textColorForBackgroundColor#1031
9larsons merged 2 commits into
TryGhost:mainfrom
thomasjlee:always-blue

Conversation

@thomasjlee

@thomasjlee thomasjlee commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes textColorForBackgroundColor using Color.b(), which returns the Lab blue-yellow channel rather than the RGB blue channel. The YIQ calculation now uses Color.blue().

Supersedes #905 and fixes TryGhost/Ghost#27797.

Changes

  • Replaces .b() with .blue() in the Color Utils source.
  • Rebuilds the CJS, ES, UMD, and source-map artifacts.
  • Retains the distinguishing #cccccc regression case and updates its expected contrast text from white to black.

Validation

  • yarn workspace @tryghost/color-utils build

  • yarn workspace @tryghost/color-utils test — 11 tests passed with 100% coverage

  • yarn test — lint and tests passed across all 17 SDK packages

  • There's a clear use-case for this code change

  • Commit messages have short titles and reference the relevant issue

  • The build, lint, and tests pass

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

Updated textColorForBackgroundColor to use backgroundColor.blue() in the YIQ contrast calculation across source and generated builds. Updated the #cccccc test to expect black text.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Possibly related issues

  • TryGhost/Ghost issue 27797 — Addresses the same .b() versus .blue() typo that caused incorrect contrast text colors.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement the linked issue's required fix by using the RGB blue channel and adding regression coverage.
Out of Scope Changes check ✅ Passed The changes are limited to the color utility implementation, generated artifacts, and related regression tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly and concisely describes the change from .b() to .blue() in textColorForBackgroundColor.
Description check ✅ Passed The description explains the bug, implementation change, regression coverage, linked issues, and validation results.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

…call Color.blue()

refs Ghost (core) Issue #27797
- deleted test that was asserting the buggy behavior
refs TryGhost/Ghost#27797

Kept the distinguishing #cccccc case and updated its expected result so reverting from Color.blue() to the Lab b-channel fails the package tests.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (0b21bed) to head (c79be97).
⚠️ Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1031   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           30        30           
  Lines         3060      3060           
  Branches       459       459           
=========================================
  Hits          3060      3060           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@9larsons 9larsons left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the corrected RGB blue-channel implementation and generated artifacts. Added regression coverage that fails if Color.b() is reintroduced. The Color Utils build/tests, SDK-wide lint/tests, and upstream Node 20/22 checks all pass.

@9larsons
9larsons merged commit 2e418fe into TryGhost:main Aug 10, 2026
3 checks passed
9larsons added a commit that referenced this pull request Aug 10, 2026
refs #1031
refs TryGhost/Ghost#27797

Covered the reported lavender, pink, and blue backgrounds plus grays surrounding the YIQ threshold without changing existing assertions.
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.

{{contrast_text_color}} helper returns incorrect text color

3 participants