Skip to content

Theme: Warn about focus ring and brand fill contrast - #85449

Merged
ciampo merged 7 commits into
trunkfrom
codex/theme-enforce-focus-contrast
Oct 27, 2026
Merged

ciampo merged 7 commits into
trunkfrom
codex/theme-enforce-focus-contrast

Conversation

@ciampo

@ciampo ciampo commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #85448. See #84087.

What?

Report focus-ring and strong brand fill colors below 3:1 contrast against neutral and brand surfaces through ThemeProvider.onColorWarnings.

Why?

Readable text on a solid popup highlight does not guarantee that the highlight is distinguishable from its surroundings.

How?

Check the final generated ring, resting fill, and active fill against all three neutral surfaces and the public brand surface after seed adjustments. These checks report failures without changing the colors. Existing text checks keep their 4.5:1 target.

The README explains the default resting-fill contrast failures on background #1e1e1e and how to choose a different primary or background seed. A focused regression checks the existing ring contrast across generated light, dark, and colored ramps.

Testing Instructions

  1. Open Design System → Theme → Theme Provider → Color Scales → Default in Storybook. Primary #3858e9 with background #fcfcfc should report no warnings.
  2. Set background to #1e1e1e. Expect resting strong brand fill warnings at approximately 2.97:1 against the neutral surface and 2.76:1 against the neutral strong surface. The focus ring remains #8eb0ff; the ring, active fill, and text checks pass.
  3. Keep the default primary and set background to #000000. The warnings should clear.
  4. Set primary to #608010 and background to #4f386e. Expect a warning for the final active fill #6e8f26 against neutral strong #563b79, at approximately 2.45:1.
  5. Set primary to #ffff00 and background to #fcfcfc. Expect 3:1 warnings for the solid fills while their text remains readable.
Verification

All 291 tests selected by packages/theme passed, including Chromium. The production build, theme typecheck, JavaScript lint, and changelog validation passed. Coverage includes the unrounded 3:1 warning threshold, final fills after seed adjustment, provider callback delivery, and ring contrast across generated ramps.

Use of AI Tools

Codex was used to investigate the contrast checks, implement the final-color warnings, tests, and documentation, run verification, and draft this description.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: +76 B (0%)

Total Size: 8.56 MB

📦 View Changed
Filename Size Change
build/scripts/theme/index.min.js 27 kB +76 B (+0.28%)

1c7315d Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric c40db6c trunk % Change
timeToFirstByte 53.85 ms +16.62% -4.09% 54.2 ms +8.49% -4.52% -0.65%
largestContentfulPaint 94 ms +2.13% -8.51% 92 ms +4.35% -8.7% 2.17%
lcpMinusTtfb 33.7 ms +17.95% -3.71% 33.45 ms +17.19% -1.94% 0.75%
wpBeforeTemplate 28.37 ms +21.47% -2.43% 28.5 ms +9.61% -2.35% -0.46%
wpTemplate 20.94 ms +4.39% -4.3% 21.42 ms +4.81% -8.31% -2.24%
wpTotal 50.28 ms +15.19% -4.24% 50.62 ms +8.53% -5.1% -0.67%
wpMemoryUsage 7.70 MB +0% -0% 7.67 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric c40db6c trunk % Change
timeToFirstByte 41 ms +6.95% -1.46% 46.25 ms +6.27% -2.16% -11.35%
largestContentfulPaint 90 ms +4.44% -2.22% 100 ms +4% -0% -10%
lcpMinusTtfb 48.05 ms +4.06% -1.04% 54.55 ms +2.75% -2.2% -11.92%
wpBeforeTemplate 26.28 ms +2.74% -1.41% 26.47 ms +11.22% -1.55% -0.72%
wpTemplate 11.89 ms +4.54% -1.85% 16.31 ms +2.39% -1.41% -27.1%
wpTotal 38.32 ms +6.84% -1.49% 43.11 ms +6.45% -1.99% -11.11%
wpMemoryUsage 6.28 MB +0% -0% 6.36 MB +0% -0% -1.22%
wpDbQueries 9 +0% -0% 13 +0% -0% -30.77%

media-processing

Metric c40db6c trunk % Change
mediaProcessingJpeg 402.94 ms +0.97% -0.79% 403.83 ms +0.21% -1.7% -0.22%
mediaProcessingAvif 6097.32 ms +0.25% -0.11% 6113.17 ms +0.17% -0.1% -0.26%
mediaProcessingJpegToAvif 4222.1 ms +0.21% -0.06% 4235.31 ms +0.35% -0.15% -0.31%

media-upload

Metric c40db6c trunk % Change
jpegUploadProcessing 1439.28 ms +1.51% -0.99% 1429.34 ms +0.38% -1.2% 0.7%
pngUploadProcessing 239.99 ms +7.29% -1.82% 189.32 ms +19.25% -4.91% 26.76%
largeJpegUploadProcessing 1428.99 ms +0.99% -0.47% 1420.23 ms +0.41% -0.3% 0.62%
multipleImageUploadProcessing 1496.16 ms +0.79% -0.58% 1480.79 ms +1.24% -0.3% 1.04%

post-editor

Metric c40db6c trunk % Change
serverResponse 490.24 ms +4.19% -3.06% 510.58 ms +5.36% -5.64% -3.98%
firstPaint 503.72 ms +8.62% -46.2% 488.94 ms +5.13% -41.63% 3.02%
domContentLoaded 900.64 ms +0.81% -2.24% 884.24 ms +1.72% -1.74% 1.85%
loaded 901.99 ms +0.81% -2.27% 885.38 ms +1.73% -1.76% 1.88%
firstContentfulPaint 515.2 ms +6.2% -8.19% 510.01 ms +2.91% -6.02% 1.02%
firstBlock 3059.52 ms +3.49% -2.83% 3023.24 ms +2.1% -1.11% 1.2%
type 17.22 ms +3.95% -1.16% 17.56 ms +8.49% -1.94% -1.94%
typeWithoutInspector 16.93 ms +5.61% -2.78% 18.1 ms +9.72% -7.07% -6.46%
typeWithTopToolbar 24.43 ms +3.77% -3.93% 22.94 ms +3.57% -3.14% 6.5%
typeContainer 8.69 ms +2.3% -6.79% 8.65 ms +9.71% -7.63% 0.46%
focus 118.6 ms +16.95% -5.84% 120.03 ms +3.24% -6.62% -1.19%
firstFocus 233.76 ms +0% -0% 238.44 ms +0% -0% -1.96%
selectAll 508.55 ms +0.99% -3.22% 530.59 ms +2.15% -6.72% -4.15%
listViewOpen 80.37 ms +12.84% -8.31% 80.49 ms +9.45% -4.3% -0.15%
inserterOpen 43.5 ms +14.57% -10.71% 43.29 ms +11.76% -6.75% 0.49%
inserterHover 11.82 ms +7.36% -13.03% 11.51 ms +8.51% -8.34% 2.69%
inserterSearch 7.83 ms +4.34% -2.04% 8.21 ms +5.48% -10.23% -4.63%
loadPatterns 648.42 ms +2.74% -2.03% 636.15 ms +7.01% -2.17% 1.93%
wpTotal 480.59 ms +4.3% -3.03% 501.14 ms +5.4% -5.81% -4.1%
wpMemoryUsage 14.75 MB +0% -0% 14.72 MB +0% -0% 0.24%
wpDbQueries 55 +0% -1.82% 55 +0% -1.82% 0%

site-editor

Metric c40db6c trunk % Change
serverResponse 498.06 ms +4.12% -6.98% 504.38 ms +7.35% -5.96% -1.25%
firstPaint 316.16 ms +15.37% -13.77% 286.67 ms +6.53% -5.84% 10.29%
domContentLoaded 913.73 ms +0.95% -0.83% 931.88 ms +0.95% -1.57% -1.95%
loaded 914.92 ms +0.94% -0.84% 932.98 ms +0.99% -1.53% -1.94%
firstContentfulPaint 513.68 ms +1.82% -1.52% 509.6 ms +3.26% -1% 0.8%
firstBlock 4022.42 ms +1.49% -0.4% 4041.46 ms +1.23% -1.35% -0.47%
type 18.5 ms +6.7% -2.05% 18.44 ms +4.39% -1.57% 0.33%
navigate 122.12 ms +11.57% -0.93% 121.87 ms +6.11% -1.49% 0.21%
loadPatterns 1265.35 ms +5.4% -8.15% 1219.07 ms +8.63% -4.6% 3.8%
loadPages 971.04 ms +3.52% -1.49% 997.33 ms +1.26% -6.28% -2.64%
wpTotal 488.79 ms +4.14% -7.06% 494.7 ms +7.52% -6.05% -1.19%
wpMemoryUsage 12.77 MB +0% -0% 12.74 MB +0% -0% 0.24%
wpDbQueries 44 +2.27% -0% 44 +2.27% -0% 0%

1c7315d Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

As a user I want to be able to add multiple close buttons so that users can close the overlay from different positions in /test/e2e/specs/site-editor/navigation-overlay-template-part.spec.js, passed after 1 failed attempt.
Error: expect(locator).toHaveCount(expected) failed

Locator:  getByRole('button', { name: 'Close' })
Expected: 2
Received: 1
Timeout:  5000ms

Call log:
  - Expect "toHaveCount" getByRole('button', { name: 'Close' }) with timeout 5000ms
  - waiting for getByRole('button', { name: 'Close' })
    14 × locator resolved to 1 element
       - unexpected value "1"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/site-editor/navigation-overlay-template-part.spec.js:228:33
Delete (forward) in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  -  2
+ Received  + 25

@@ -1,25 +1,48 @@
  Array [
    Object {
      "innerBlocks": Array [
        Object {
          "attributes": Object {
-           "content": "1",
+           "content": "‸",
          },
          "innerBlocks": Array [
            Object {
+             "attributes": Object {
+               "ordered": false,
+               "values": "",
+             },
              "innerBlocks": Array [
                Object {
                  "attributes": Object {
-                   "content": "a‸2",
+                   "content": "a",
                  },
+                 "innerBlocks": Array [],
                  "name": "core/list-item",
+               },
+             ],
+             "name": "core/list",
            },
+         ],
+         "name": "core/list-item",
+       },
+       Object {
+         "attributes": Object {
+           "content": "2",
+         },
+         "innerBlocks": Array [
            Object {
              "attributes": Object {
+               "ordered": false,
+               "values": "",
+             },
+             "innerBlocks": Array [
+               Object {
+                 "attributes": Object {
                    "content": "b",
                  },
+                 "innerBlocks": Array [],
                  "name": "core/list-item",
                },
              ],
              "name": "core/list",
            },

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:2056:42
moves selected text into another paragraph in /test/e2e/specs/editor/various/draggable-blocks.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  -  2
+ Received  + 14

  Array [
    Object {
      "attributes": Object {
-       "content": "First third",
+       "content": "second",
+       "dropCap": false,
      },
+     "innerBlocks": Array [],
      "name": "core/paragraph",
    },
    Object {
      "attributes": Object {
-       "content": "Fourth second fifth",
+       "content": "First second third",
+       "dropCap": false,
+     },
+     "innerBlocks": Array [],
+     "name": "core/paragraph",
    },
+   Object {
+     "attributes": Object {
+       "content": "Fourth fifth",
+       "dropCap": false,
+     },
+     "innerBlocks": Array [],
      "name": "core/paragraph",
    },
  ]

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/draggable-blocks.spec.js:1167:41
passes the search value in the main inserter when clicking `Browse all` in /test/e2e/specs/editor/various/inserting-blocks.spec.js, passed after 1 failed attempt.
TimeoutError: locator.fill: Timeout 10000ms exceeded.
Call log:
  - waiting for getByRole('searchbox', { name: 'Search' }).first()

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/inserting-blocks.spec.js:763:5
should be immediately saved on indentation in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 1
+ Received  + 1

@@ -1,8 +1,8 @@
  <!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
- <li>one<!-- wp:list -->
+ <li>e<!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
  <li></li>
  <!-- /wp:list-item --></ul>
  <!-- /wp:list --></li>
  <!-- /wp:list-item --></ul>

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:694:52
should create paragraph on split at end and merge back with content in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 1
+ Received  + 1

@@ -1,8 +1,8 @@
  <!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
- <li>one</li>
+ <li>ne</li>
  <!-- /wp:list-item --></ul>
  <!-- /wp:list -->

  <!-- wp:paragraph -->
  <p></p>

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:461:52
should cut and paste individual blocks with collapsed selection in /test/e2e/specs/editor/various/copy-cut-paste.spec.js, passed after 1 failed attempt.
Error: expect(string).toMatchSnapshot(expected) failed

  @@ -1,3 +1,3 @@
   <!-- wp:paragraph -->
  -<p>2Cut - collapsed selection</p>
  +<p>2</p>
   <!-- /wp:paragraph -->


    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/copy-cut-paste.spec.js:45:49
should indent and outdent level 1 in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for locator('role=toolbar[name="Block tools"i]').locator('role=button[name="Indent"]')

    at Editor.clickBlockToolbarButton (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/editor/click-block-toolbar-button.ts:17:15)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:775:3
should indent and outdent multi-selected items with Tab in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 1
+ Received  + 1

@@ -1,8 +1,8 @@
  <!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
- <li>one<!-- wp:list -->
+ <li>ne<!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
  <li>two</li>
  <!-- /wp:list-item -->

  <!-- wp:list-item -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:1118:52
should indent with Space and outdent with Shift+Space at the start in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 7
+ Received  + 7

  <!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
- <li>a<!-- wp:list -->
- <ul class="wp-block-list"><!-- wp:list-item -->
- <li>b</li>
+ <li></li>
+ <!-- /wp:list-item --></ul>
- <!-- /wp:list-item --></ul>
+ <!-- /wp:list -->
+
- <!-- /wp:list --></li>
- <!-- /wp:list-item --></ul>
+ <!-- wp:paragraph -->
+ <p> b</p>
- <!-- /wp:list -->
+ <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:875:52
should insert a line break on shift+enter in a non trailing list item in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 10
+ Received  + 10

  <!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
- <li>a</li>
+ <li></li>
- <!-- /wp:list-item -->
-
+ <!-- /wp:list-item --></ul>
- <!-- wp:list-item -->
+ <!-- /wp:list -->
+
+ <!-- wp:paragraph -->
- <li>b<br></li>
+ <p>b<br></p>
- <!-- /wp:list-item -->
+ <!-- /wp:paragraph -->

- <!-- wp:list-item -->
+ <!-- wp:paragraph -->
- <li>c</li>
+ <p>c</p>
- <!-- /wp:list-item --></ul>
- <!-- /wp:list -->
+ <!-- /wp:paragraph -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:1233:52
should insert a line break on shift+enter in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 1
+ Received  + 1

  <!-- wp:list -->
  <ul class="wp-block-list"><!-- wp:list-item -->
- <li>a<br></li>
+ <li><br></li>
  <!-- /wp:list-item --></ul>
  <!-- /wp:list -->

Call Log:
- Timeout 5000ms exceeded while waiting on the predicate
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:1210:52
should insert mention in a table block in /test/e2e/specs/editor/various/autocomplete-and-mentions.spec.js, passed after 2 failed attempts.
Error: apiRequestContext.fetch: socket hang up
Call log:
  - → DELETE http://localhost:8889/wp-json/wp/v2/users/30?force=true&reassign=1
    - user-agent: Playwright/1.63.0 (x64; ubuntu 24.04) node/24.20 CI/1
    - accept: */*
    - accept-encoding: gzip,deflate,br
    - X-WP-Nonce: a87c440641
    - cookie: wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_23778236db82f19306f247e20a353a99=admin%7C1793294853%7CGiyQqYpETzrEAaVBJvWnrXCybzyrPnxGI7GUxJM9yO9%7C2c265222e0da75c412f2b10dbf16ac20e036313e85a839b07890f1fa87a5abf2; wp-settings-time-1=1793122775

    at RequestUtils.rest (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/rest.ts:111:39)
    at RequestUtils.deleteUser (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/users.ts:91:30)
    at map (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/users.ts:116:51)
    at RequestUtils.deleteAllUsers (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/request-utils/users.ts:116:5)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/autocomplete-and-mentions.spec.js:73:3

should keep a full selection when outdenting nested items with Shift+Tab in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
TimeoutError: locator.click: Timeout 10000ms exceeded.
Call log:
  - waiting for locator('role=toolbar[name="Block tools"i]').locator('role=button[name="Indent"]')

    at Editor.clickBlockToolbarButton (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils-playwright/src/editor/click-block-toolbar-button.ts:17:15)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:1166:3
should leave the rest of the list intact when merging into an empty list item in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  -  0
+ Received  + 13

@@ -5,27 +5,40 @@
          "attributes": Object {
            "content": "1",
          },
          "innerBlocks": Array [
            Object {
+             "attributes": Object {
+               "ordered": false,
+               "values": "",
+             },
              "innerBlocks": Array [
                Object {
                  "attributes": Object {
                    "content": "a",
                  },
+                 "innerBlocks": Array [],
                  "name": "core/list-item",
                },
                Object {
                  "attributes": Object {
                    "content": "b",
                  },
+                 "innerBlocks": Array [],
                  "name": "core/list-item",
                },
              ],
              "name": "core/list",
            },
          ],
+         "name": "core/list-item",
+       },
+       Object {
+         "attributes": Object {
+           "content": "",
+         },
+         "innerBlocks": Array [],
          "name": "core/list-item",
        },
      ],
      "name": "core/list",
    },
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/list.spec.js:3118:38
should merge a following sibling list into the outermost list with Delete from a nested item (#77245) in /test/e2e/specs/editor/blocks/list.spec.js, passed after 1 failed attempt.
Error: expect(received).toMatchObject(expected)

- Expected  - 2
+ Received  + 2

Truncated. See the full report.

1c7315d Run

@ciampo ciampo self-assigned this Oct 23, 2026
@ciampo ciampo added the [Type] Enhancement A suggestion for improvement. label Oct 23, 2026
@ciampo
ciampo marked this pull request as ready for review October 23, 2026 13:49
@ciampo
ciampo requested a review from a team as a code owner October 23, 2026 13:49
Comment on lines 366 to 398
// Fit the seed to the original ramp targets first. A focus constraint must
// not move the seed and change otherwise accessible fill/foreground pairs.
const additionalReferenceColors =
getAdditionalReferenceColors?.( bestRamp );
const needsFinalConstraints = Object.entries(
additionalReferenceColors ?? {}
).some( ( [ rawStep, extraRefs ] ) => {
const step = rawStep as keyof Ramp;
const contrast = config[ step ].contrast;
const internalRefs = [
contrast.reference,
...( contrast.additionalReferences ?? [] ),
].map( ( name ) =>
name === 'seed' ? getColorString( finalSeed ) : bestRamp[ name ]
);
return [ ...internalRefs, ...( extraRefs ?? [] ) ].some(
( reference ) =>
getContrast( bestRamp[ step ], reference ) < contrast.target
);
} );
if ( needsFinalConstraints ) {
const finalResult = calculateRamp( {
seed: finalSeed,
sortedSteps,
config,
mainDir,
oppDir,
pinLightness,
additionalReferenceColors,
} );
bestRamp = finalResult.rampResults;
bestWarnings = finalResult.warnings;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I couldn't find an input where this second pass changes the ramp. Against trunk, 1,500 random primary/background pairs and 3,888 mid-lightness backgrounds gave identical colors, and the ring never fell below 3:1 against the four surfaces. The tests only reach it by overwriting neutral.ramp.surface3, which buildBgRamp can't produce.

Would it make sense to drop the correction and the serialized-contrast mode, and guard the invariant with a test over generated ramps instead? The new warnings already report a failure at runtime.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I removed the correction pass and serialized-contrast mode. The final-color warnings stay, with a regression test over generated ramps.

// These colors identify focus through a ring or a solid item highlight. Check
// every supported neutral surface and the public brand surface using the final
// colors, including any focus-ring correction.
export const SEMANTIC_FOCUS_CONTRAST_PAIRS = (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With the default primary on #1e1e1e (the README's dark example), this now reports brand-strong (#3858e9) at 2.97:1 against surface.neutral and 2.76:1 against surface.neutral-strong. Fills are never adjusted, so anyone using the default brand color in a dark theme gets warnings they can only clear by changing the brand color.

This contrast problem is already known, as we discussed, but the new warning perhaps makes the consumer experience worse by being confusing. Until we fix the contrast issue, we probably need some kind of guidance to let them know that the default primary doesn't work in dark mode.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added README guidance for the resting-fill warnings in the default dark example, including a passing background alternative. It also clarifies that the ring, active fill, and text still meet their targets.

Comment thread packages/theme/CHANGELOG.md Outdated

### Enhancements

- Enforce the 3:1 focus-ring contrast target against neutral and brand surfaces after seed adjustment while preserving fill and foreground colors ([#85449](https://github.com/WordPress/gutenberg/pull/85449)).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If the correction goes, this entry goes with it. If it stays, "while preserving fill and foreground colors" describes unchanged behavior, so I'd drop that part.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed the correction entry, leaving only the new contrast warnings in the changelog.

@ciampo ciampo changed the title Theme: Enforce focus ring contrast against theme surfaces Theme: Warn about focus ring and brand fill contrast Oct 23, 2026
@ciampo
ciampo requested a review from mirka October 23, 2026 21:06
@ciampo
ciampo enabled auto-merge (squash) October 27, 2026 12:21
@ciampo
ciampo merged commit 81a4645 into trunk Oct 27, 2026
81 checks passed
@ciampo
ciampo deleted the codex/theme-enforce-focus-contrast branch October 27, 2026 17:45
@github-actions github-actions Bot added this to the Gutenberg 24.4 milestone Oct 27, 2026
Vedant-Gandhi pushed a commit to Vedant-Gandhi/gutenberg that referenced this pull request Nov 30, 2026
* Theme: Enforce focus ring contrast against theme surfaces

* Theme: Document focus contrast enforcement

* Theme: Warn about final popup fill contrast

* Theme: Trim overlapping contrast test cases

* Theme: Keep final contrast warnings without automatic correction

---

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: mirka <0mirka00@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Theme /packages/theme [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants