Repository navigation
Conversation
mikeharv
marked this pull request as ready for review
November 23, 2026 19:34
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The basics
The details
Resolves
Fixes #1640
Proposed Changes
Changes the text colour to black on blocks that don't pass a minimum contrast threshold. Users whose OS asks for more contrast get some new colours by default; for everyone else nothing changes unless the app raises
config.textContrast.New internal Colour utils
getLuminance,getContrastRatioandgetReadableTextColourare added. These are used to measure and compare colours and ultimately choose a readable colour for text, e.g. on very bright blocks.Calculations were implemented by Claude to reproduce those defined by W3C for WCAG compliance:
New Accessibility Util
shouldIncreaseContrastreads from OS settings, similar toshouldReduceMotion, introduced in fix: Respect reduce motion a11y preference #10672Implementation in Core Blockly
#10672 just turns off CSS transitions with a
@mediarule, but adjusting the colour contrast has to be done in JS, with the resulting colour passed through to CSS. For this it uses--blockly-block-foreground. This name was chosen because I plan to use it for both text and icons (the latter being needed for the lesson authoring work).BlockSvgs can now choose a different text colour viaupdateForegroundColour. The background colour is found by looking at the fill ofsvgPathrather than the block style to account for full-block fields. Disabled blocks are always light gray (#aaa) and handled as well.To choose a text colour, the utils check the background colour contrast with white. Black is used if white falls short of the contrast ratio indicated by two new
configfields and OS setting.The text and icon colour must be applied after fields are coloured due to how full-block fields work.
Similarly, dropdowns perform these calculations while their menus are open, because the text at that point sits on a different (tertiary) coloured rect.
New config fields
Two new
configfields,textContrastandincreasedTextContrastwere added. The former enforces a default contrast for all users while the latter does the same for users who have asked their OS for increased contrast. The current defaulttextContrastis 1, which means any contrast is allowed. I'd recommend bumping this to 3 with the v14 launch, as this is the WCAG recommendation for large text and graphics. The defaultincreasedTextContrastis 4.5 which is the WCAG minimum contrast ratio for normal-sized text. Applications can override either of theseconfigfields before they inject. To avoid surprising developers and application end-users with suddenly new text colours, these changes are currently opt-in for users who haven't already asked for increased contrast.Below is a screenshot of various blocks from core that use black text where contrast would otherwise be below 4.5:1.

Reason for Changes
Currently, block text is white, even on white or other brightly coloured blocks, which makes text hard to read and is a WCAG violation.
Test Coverage
Unit tests were added for the new colour utils.
A new
block_foreground_test.tswas added which check for the expected text color with a variety of blocks (including disabled, full-block field, and shadow) using a 3:1 ratio.Contrast sliders were added to the Advanced Playground.
Documentation
I verified that the new config values show up locally in docs where expected (
reference/variables/config/).Additional Information
I'd recommend bumping
config.textContrastto 3 with the v14 launch, as this is the WCAG recommendation for large text and graphics.Claude helped draft some of the code, especially the new colour utils and tests. It also identified the right source of truth for background colors and the zelos dropdown use case. Everything was tested thoroughly and all AI generated code was reviewed carefully.