Skip to content

Comments

Remove theme toggle, use browser color scheme#16781

Merged
Mossaka merged 1 commit intomainfrom
feat/editor-auto-theme
Feb 19, 2026
Merged

Remove theme toggle, use browser color scheme#16781
Mossaka merged 1 commit intomainfrom
feat/editor-auto-theme

Conversation

@Mossaka
Copy link
Collaborator

@Mossaka Mossaka commented Feb 19, 2026

Summary

  • Removed the sun/moon theme toggle button from the playground editor header
  • The editor now automatically follows the browser's prefers-color-scheme preference (light or dark mode)
  • Primer CSS already supports data-color-mode="auto" on the <html> element, so page styles adapt natively
  • CodeMirror themes (oneDark vs default) switch via a matchMedia listener

Test plan

  • Open the playground in a browser set to light mode — verify light theme renders
  • Switch OS/browser to dark mode — verify both Primer styles and CodeMirror switch to dark
  • Confirm no sun/moon button appears in the header

🤖 Generated with Claude Code

The editor now follows the browser's prefers-color-scheme media query
instead of providing a manual sun/moon toggle button. Primer CSS already
supports data-color-mode="auto", so we just needed to remove the manual
override and wire CodeMirror's theme to the media query listener.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 19, 2026 08:00
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

Removes the manual theme toggle from the playground editor UI and switches theming to follow the browser/OS prefers-color-scheme setting automatically, using Primer’s data-color-mode="auto" for page styles and a matchMedia listener for CodeMirror.

Changes:

  • Removed the sun/moon theme toggle button from the editor header.
  • Dropped localStorage-driven theme persistence and manual toggling logic.
  • Added a prefers-color-scheme listener to reconfigure CodeMirror themes at runtime.

Reviewed changes

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

File Description
docs/public/editor/index.html Removes the theme toggle button from the header; keeps data-color-mode="auto" on <html> for Primer auto theming.
docs/public/editor/editor.js Simplifies theme logic to follow prefers-color-scheme and updates CodeMirror theme via matchMedia changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

}
});
// Listen for OS theme changes and update CodeMirror accordingly
darkMq.addEventListener('change', () => applyCmTheme());
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.

MediaQueryList.addEventListener('change', …) isn’t supported in some browsers (notably older Safari); calling it can throw and break the editor. Consider adding a compatibility fallback (e.g., use addListener when addEventListener is unavailable) so the playground still works across the browsers the docs site targets.

Suggested change
darkMq.addEventListener('change', () => applyCmTheme());
if (darkMq && typeof darkMq.addEventListener === 'function') {
darkMq.addEventListener('change', () => applyCmTheme());
} else if (darkMq && typeof darkMq.addListener === 'function') {
darkMq.addListener(applyCmTheme);
}

Copilot uses AI. Check for mistakes.
@Mossaka Mossaka merged commit 417eaf1 into main Feb 19, 2026
49 checks passed
@Mossaka Mossaka deleted the feat/editor-auto-theme branch February 19, 2026 08:03
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.

1 participant