Skip to content

Comments

feat: Add overlay header text color setting#275

Open
jnealey88 wants to merge 6 commits intomainfrom
claude/overlay-header-text-color
Open

feat: Add overlay header text color setting#275
jnealey88 wants to merge 6 commits intomainfrom
claude/overlay-header-text-color

Conversation

@jnealey88
Copy link
Owner

Summary

  • Adds a per-page Overlay Text Color setting to the existing "Header Display" panel in the editor sidebar
  • Uses the theme's color palette (stores a slug like base or contrast), so it adapts when themes change
  • Color picker appears conditionally only when the overlay toggle is enabled, and auto-clears when disabled
  • On the frontend, outputs a CSS custom property (--dsgo-overlay-header-text-color) that applies to nav links, site title, and SVG icons in the non-scrolled overlay state
  • When the user scrolls past the threshold, the existing sticky header scroll text color takes over seamlessly

Changes

  • includes/class-overlay-header.php — New TEXT_COLOR_META_KEY constant, meta registration, get_overlay_text_color_css() method, and enqueue_overlay_styles() hook
  • src/overlay-header/index.js — Added ColorPalette control with slug↔hex conversion, wrapped in BaseControl with label/help text
  • src/styles/utilities/_sticky-header.scss — New overlay text color rules scoped to :not(.dsgo-scrolled) state
  • tests/phpunit/overlay-header-test.php — 12 new tests covering meta registration, sanitization, CSS output guards, and hook wiring

Test plan

  • Build passes (npm run build)
  • All linters pass (JS, CSS, PHP)
  • PHPUnit: 30 tests, 43 assertions pass
  • Editor: Toggle overlay on → color palette appears; toggle off → palette disappears and color resets
  • Editor: Select a theme color (e.g., "Base") → save → verify meta stored via REST API
  • Frontend: Page with overlay + text color set → header nav/title shows chosen color on transparent state
  • Frontend: Scroll past threshold → text color transitions to sticky header scroll text color
  • Frontend: Page without overlay enabled → no overlay text color CSS output in source

🤖 Generated with Claude Code

jnealey88 and others added 4 commits February 18, 2026 19:04
Adds TEXT_COLOR_META_KEY constant and registers dsgo_overlay_header_text_color
meta for all public post types (excluding attachment) with sanitize_key callback,
REST API exposure, and capability-based auth.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds get_overlay_text_color_css() to generate a scoped CSS rule that
sets --dsgo-overlay-header-text-color from the stored WP color preset
slug, and enqueue_overlay_styles() to attach it as inline CSS to the
designsetgo-sticky-header handle when the overlay is active on a
singular page.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 19, 2026 02:21
@claude
Copy link

claude bot commented Feb 19, 2026

Claude finished @jnealey88's task in 4m 20s —— View job


PR #275 Review: feat: Add overlay header text color setting

Tasks

  • Gather context and understand request
  • Read CLAUDE.md for repo guidelines
  • Fetch PR diff
  • Review PHP changes (includes/class-overlay-header.php)
  • Review JS changes (src/overlay-header/index.js)
  • Review SCSS changes (src/styles/utilities/_sticky-header.scss)
  • Review test changes (tests/phpunit/overlay-header-test.php)
  • Post inline comments on specific issues
  • Post final summary

Review complete — 0 Critical / 0 High / 2 Medium / 3 Low

The implementation is solid overall. Full summary posted as a PR review above. Inline comments on three specific lines:

  • SCSS line 319 — Missing wp-block-navigation-item__content / wp-block-navigation-item__label selectors (Medium)
  • PHP line 133 — Redundant sanitize_key call (Low)
  • JS line 100BaseControl id doesn't connect to ColorPalette (Low)

The one Medium issue not addressable via inline comment (because it touches an unchanged block): the new transition: color/fill rules in the overlay text color block need matching entries in the existing @media (prefers-reduced-motion: reduce) block at lines 148–162.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a per-page overlay text color setting to the Header Display panel in the editor, allowing users to customize header text color when the overlay header feature is enabled. The color is stored as a theme color slug (e.g., "base", "contrast") for theme portability, and is applied only in the non-scrolled overlay state via CSS custom properties.

Changes:

  • Adds overlay text color meta field registration and CSS generation in the backend PHP class
  • Implements color picker UI in the editor with automatic slug-to-hex conversion
  • Applies color styles via CSS custom properties scoped to the non-scrolled overlay state
  • Includes comprehensive test coverage for meta registration, CSS output guards, and hook wiring

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
includes/class-overlay-header.php Adds TEXT_COLOR_META_KEY constant, meta registration with sanitization, CSS generation method, and enqueue hook
src/overlay-header/index.js Adds ColorPalette control with slug↔hex conversion logic, conditionally displayed when overlay is enabled
src/styles/utilities/_sticky-header.scss Adds CSS rules for overlay text color targeting nav links, site title, and SVG icons in non-scrolled state
tests/phpunit/overlay-header-test.php Adds 12 new tests covering constant values, meta registration, sanitization, CSS output conditions, and hook verification

transition: fill var(--dsgo-sticky-header-transition-speed, 300ms) ease-in-out;
}
}

Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

The new overlay text color transitions should be disabled when prefers-reduced-motion is active for accessibility. The existing prefers-reduced-motion media query at lines 148-162 disables transitions for sticky header styles but doesn't include the new overlay text color selectors. Consider adding the new selectors from lines 300-328 to the prefers-reduced-motion block to respect user motion preferences.

Suggested change
@media (prefers-reduced-motion: reduce) {
body:not(.block-editor-page).dsgo-page-overlay-header .wp-block-template-part:not(footer):not(.dsgo-scrolled):first-of-type,
body:not(.block-editor-page).dsgo-page-overlay-header header.wp-block-template-part:not(.dsgo-scrolled) {
transition: none !important;
.wp-block-navigation a,
.wp-block-navigation a:hover,
.wp-block-navigation a:focus,
.wp-block-navigation a:focus-visible,
.wp-block-navigation a:visited,
.wp-block-navigation a:active,
.wp-block-site-title a,
.wp-block-site-title a:hover,
.wp-block-site-title a:focus,
.wp-block-site-title a:focus-visible,
.wp-block-site-title a:visited,
.wp-block-site-title a:active {
transition: none !important;
}
.wp-block-navigation__submenu-icon svg,
.wp-block-navigation__responsive-container-open svg {
transition: none !important;
}
}
}

Copilot uses AI. Check for mistakes.
.wp-block-site-title a:focus-visible,
.wp-block-site-title a:visited,
.wp-block-site-title a:active {
color: var(--dsgo-overlay-header-text-color, inherit);
Copy link

Choose a reason for hiding this comment

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

Medium — Missing nav-item selectors (inconsistency with .dsgo-scrolled block)

The existing .dsgo-scrolled color rules (lines ~107–115) include .wp-block-navigation-item__content, .wp-block-navigation-item__label, and .wp-block-navigation__submenu-icon (without svg), but these are absent from the new overlay text color block. Themes that set an explicit color on these elements will override color: inherit from the parent, so those items may not adopt the chosen overlay text color.

Suggested change
color: var(--dsgo-overlay-header-text-color, inherit);
.wp-block-site-title a:active {
color: var(--dsgo-overlay-header-text-color, inherit);
transition: color var(--dsgo-sticky-header-transition-speed, 300ms) ease-in-out;
}
/* Navigation item labels/content (needed for explicit color overrides) */
.wp-block-navigation-item__content,
.wp-block-navigation-item__label,
.wp-block-navigation__submenu-icon {
color: var(--dsgo-overlay-header-text-color, inherit);
}

return '';
}

$text_color_slug = sanitize_key( $text_color_slug );
Copy link

Choose a reason for hiding this comment

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

Low — Redundant sanitize_key call

The meta was already sanitized via sanitize_callback when it was stored (registered at line 77). Re-sanitizing here is harmless but unnecessary. If you're being defensive, a short comment would make the intent clear; otherwise this line can be removed.

Suggested change
$text_color_slug = sanitize_key( $text_color_slug );
$text_color_slug = get_post_meta( $post_id, self::TEXT_COLOR_META_KEY, true );

'designsetgo'
)}
>
<ColorPalette
Copy link

Choose a reason for hiding this comment

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

Low — BaseControl id doesn't connect to a focusable element

BaseControl renders a <label for="dsgo-overlay-text-color"> but ColorPalette doesn't render an <input id="dsgo-overlay-text-color">. The association is broken, so screen readers and click-on-label won't focus the control. Consider using __nextHasNoMarginBottom without specifying id, or wrapping with a <fieldset>/<legend> if you need the grouping semantics. The id is otherwise harmless from a functional standpoint.

Suggested change
<ColorPalette
<ColorPalette
colors={colors}
value={textColorHex}
onChange={updateTextColor}
clearable
Text Color', 'designsetgo')}
/>

Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

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

Code Review Summary

0 Critical / 0 High / 2 Medium / 3 Low

Overall this is a clean, well-structured implementation. The security fundamentals are solid, the test coverage is thorough, and the feature integrates naturally with the existing overlay header and sticky header systems. A few items worth addressing before merge:


Medium

1. prefers-reduced-motion not updated (src/styles/utilities/_sticky-header.scss)

The new overlay text color block adds transition: color on the container (line 303) and on each child link/site-title selector (line 320), plus transition: fill on SVG icons (line 327). The existing @media (prefers-reduced-motion: reduce) block (lines 148–162) covers the analogous .dsgo-sticky-bg-on-scroll transitions but has no entries for the new selectors. Users with reduced-motion preference will still get the color fade animation.

Suggested additions inside the prefers-reduced-motion block:

body:not(.block-editor-page).dsgo-page-overlay-header .wp-block-template-part:not(footer):not(.dsgo-scrolled):first-of-type,
body:not(.block-editor-page).dsgo-page-overlay-header header.wp-block-template-part:not(.dsgo-scrolled),
body:not(.block-editor-page).dsgo-page-overlay-header .wp-block-template-part:not(footer):not(.dsgo-scrolled):first-of-type .wp-block-navigation a,
body:not(.block-editor-page).dsgo-page-overlay-header .wp-block-template-part:not(footer):not(.dsgo-scrolled):first-of-type .wp-block-site-title a,
body:not(.block-editor-page).dsgo-page-overlay-header .wp-block-template-part:not(footer):not(.dsgo-scrolled):first-of-type svg {
    transition: none !important;
}

2. Missing nav-item selectors (inline comment on SCSS line 319)

The .dsgo-scrolled rule block includes .wp-block-navigation-item__content, .wp-block-navigation-item__label, and .wp-block-navigation__submenu-icon to override explicit theme color values. The new overlay text color block omits them, so themes that set an explicit color on those elements may not respect the overlay text color setting. See inline comment for the suggested selectors.


Low

3. Redundant sanitize_key call (class-overlay-header.php line 133, inline comment)

The value was already sanitized via sanitize_callback on write. The re-call is harmless but unnecessary — either remove it or add a brief comment explaining defensive intent.

4. BaseControl id disconnected from ColorPalette (index.js lines 93/100, inline comment)

BaseControl renders <label for="dsgo-overlay-text-color"> but ColorPalette doesn't produce a matching input element. The label click/screen reader association is broken. See inline comment for an aria-label alternative.

5. test_text_color_meta_sanitization tests the function, not the wiring (overlay-header-test.php lines 337–343)

The test verifies that sanitize_key() itself behaves correctly, not that the registered meta key is wired to use it as its sanitize callback. A test that writes an unsafe value via the REST API and asserts it is sanitized before storage would give stronger confidence. Not blocking, but worth noting.


What looks good

  • Security: sanitize_key restricts output to [a-z0-9_-], making the var(--wp--preset--color--%s) interpolation safe. wp_add_inline_style is the correct WP API. Auth callback uses current_user_can('edit_post', $post_id) correctly.
  • Architecture: Slug-based storage is the right choice — it adapts automatically when themes change, avoids storing hex values that go stale, and maps directly to the WP preset CSS custom property pattern.
  • JS color lookup: Slug↔hex conversion via the core/block-editor settings store is idiomatic; the clearable prop + !hex guard handles deselection cleanly.
  • Conditional display: The overlayEnabled && guard and auto-clear on toggle-off are both correct.
  • SCSS specificity: Using :not(.dsgo-scrolled) to limit the overlay color to the transparent state and letting the existing .dsgo-scrolled rules take over is the right approach.
  • Tests: 12 new tests, including edge cases (archive page, overlay disabled, empty slug) — solid coverage.

View job run

jnealey88 and others added 2 commits February 18, 2026 19:56
- Add overlay text color selectors to prefers-reduced-motion block
- Add missing nav-item selectors (navigation-item__content, __label,
  __submenu-icon) to match the scrolled state rules
- Add defense-in-depth comment on sanitize_key call
- Remove broken BaseControl id (ColorPalette has no matching input)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Advanced Heading patterns commit (c76fcdc) added 'headings' to
ALLOWED_CATEGORIES but the test expectation was not updated.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant