Fix #54: adopt wp-admin native scheme accent at runtime (and live preview)#72
Open
lucasmendes-design wants to merge 1 commit into
Open
Fix #54: adopt wp-admin native scheme accent at runtime (and live preview)#72lucasmendes-design wants to merge 1 commit into
lucasmendes-design wants to merge 1 commit into
Conversation
…review)
May 2026 usability testing surfaced that the redesigned sidebar's
accent didn't match wp-admin's native palette and broke when the user
switched colour schemes. The previous tokens hard-coded the Fresh
scheme's blues (#71aee2 / #3858e9), used 'SF Pro Text' (Apple-only),
and had no scheme awareness at all.
This change makes the sidebar accent follow whichever admin colour
scheme is active — built-in Fresh / Light / Modern / Blue / Coffee /
Ectoplasm / Midnight / Ocean / Sunrise, AND any third-party scheme
registered via wp_admin_css_color(). No hex values for scheme accents
in our CSS — instead, a small runtime module reads wp-admin's actual
scheme highlight from `.button-primary`'s computed background-color
and writes it into our two accent CSS custom properties on :root.
Three pieces:
1. styles.css — drop the 'SF Pro Text' font-stack entry (silently fell
through to Helvetica everywhere except Apple). Replace with
wp-admin's native system stack. Token defaults updated to the Fresh
scheme's actual native value (#2271b1) so the page renders correctly
before JS runs.
2. color-scheme-preview.js (new) — on bootstrap, probe `.button-primary`
and write `--wp-admin-sidebar-group-label-fg` and
`--wp-admin-sidebar-customizer-theme` to the actual scheme highlight.
On the Profile screen, a MutationObserver on `<link id="colors-css">`'s
href attribute catches every scheme-picker click (radio, label, or
swatch — they all funnel through the same href swap) and re-probes
after a small setTimeout so the new stylesheet has been applied.
An earlier attempt listened only to `change` on the radio inputs;
that path missed clicks on the `.color-option` wrapper because WP's
color-picker.js sets `radio.prop('checked', true)` programmatically
and `prop()` doesn't fire `change`. Watching the stylesheet swap is
the single trigger that catches every UI path.
3. browse-rail.js — dynamic import of the new module, call from
bootstrap; wp-admin-sidebar.php — new file in $bust_sources.
Removes the per-scheme `body.admin-color-*` overrides that an earlier
revision of this branch had: those duplicated values from
`wp-admin/css/colors/<scheme>/colors.min.css` and would have drifted
over time + silently mismatched third-party schemes.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Fixes #54. Linear: DES-640. Off
trunkdirectly — no stack dependencies.Summary
May 2026 usability testing surfaced three related visual issues with the redesigned sidebar:
#71aee2,#3858e9) inconsistent with wp-admin's native palette.#3858e9background.'SF Pro Text'font silently falling through to Helvetica everywhere except Apple platforms.On top of those, the sidebar accent had no awareness of wp-admin's colour-scheme system — switch from Default to Sunrise / Midnight / Ectoplasm and the rest of admin recoloured while our sidebar stayed stuck on the Fresh blue.
Approach
Read wp-admin's actual scheme highlight at runtime instead of hard-coding hex values for each scheme. The CSS keeps two accent tokens with Fresh-scheme defaults; a small JS module probes
.button-primary's computedbackground-color(the canonical scheme highlight wp-admin uses) and writes the real value into both tokens at boot. Works for every built-in scheme AND any third-party scheme registered viawp_admin_css_color().Live preview
On the Profile screen the colour-picker can swap schemes without saving. WP's
color-picker.jsupdates<link id=\"colors-css\">'shrefattribute — that's the single point every click target (radio, label, swatch) funnels through. AMutationObserveron that attribute catches every variant and re-probes after asetTimeout(100)so the new stylesheet has been applied.Why not just listen to radio
changeAn earlier revision did exactly that and turned out to be the bug source: WP's
color-picker.jssetsradio.prop('checked', true)from a.color-optionclick handler, and a programmatic jQueryprop()does NOT firechange. So clicks on the wrapper / label / swatch silently bypassed the listener. Watching the stylesheet swap is the single trigger that catches every UI path.Why not just hard-code per-scheme values in CSS
An earlier revision tried
body.admin-color-{scheme}overrides with extracted hex values. Two problems:wp-admin/css/colors/<scheme>/colors.min.cssthat would drift over time.wp_admin_css_color().What changed
src/browse-rail/styles.css— drop'SF Pro Text'from the font stack (use wp-admin's native system stack). Token defaults updated to Fresh-scheme actuals (#2271b1). Comment block at top rewritten to describe the runtime-token approach.src/browse-rail/color-scheme-preview.js(new) —applyColorSchemePreview()exported, called from bootstrap. Probes.button-primaryonce on load, thenMutationObserverre-probes after eachcolors-csshref swap.src/browse-rail/browse-rail.js— dynamic import of the new module + call from bootstrap.wp-admin-sidebar.php— new file in the\$bust_sourcesarray so its mtime feeds the cache-bust query.Manual verification
Local Studio site (PHP 8.4 / WP 6.9.4, SQLite). Verified across saved and preview states on all nine built-in admin colour schemes.
#dd823borange; Midnight →#e14d43red; Modern →#3858e9purple-blue; etc.).#3858e9(which testers called "hard to read") replaced with the scheme's primary action colour —#2271b1in Fresh, matching.button-primaryeverywhere.Tests
JS-only logic + CSS values. No existing test asserts the scheme-driven token values (they're runtime). PHP suites not run locally (Studio's PHP is WASM-only); CI gates the rest.
🤖 Generated with Claude Code