Skip to content

Align theme toggle with system preference and react to prefers-color-scheme changes#186

Open
Copilot wants to merge 6 commits into
mainfrom
copilot/change-theme-toggle-behaviour
Open

Align theme toggle with system preference and react to prefers-color-scheme changes#186
Copilot wants to merge 6 commits into
mainfrom
copilot/change-theme-toggle-behaviour

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 3, 2026

Theme selection now treats browser/OS preference as the default mode instead of always persisting manual toggles. When a user-selected theme matches prefers-color-scheme, the override is removed so future system changes are reflected automatically.

  • Behavior model

    • Introduced explicit resolution flow:
      • stored theme (if different from system) wins
      • otherwise system preference wins
    • Added normalization to clear legacy/local overrides that equal current system preference.
  • Toggle semantics

    • Updated toggle handler to persist only true overrides.
    • If the toggled value equals current system preference, localStorage.theme is removed (return to system-following mode).
  • Live system theme updates

    • Added matchMedia('(prefers-color-scheme: dark)') change listener.
    • On system theme change, re-applies theme only when no explicit override is stored.
<script>
  var colorSchemeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');

  function getSystemTheme() {
    return colorSchemeMediaQuery.matches ? 'dark' : 'light';
  }

  function getTheme() {
    return localStorage.getItem('theme') || getSystemTheme();
  }

  document.getElementById('theme-toggle').addEventListener('click', function() {
    var next = document.documentElement.getAttribute('data-bs-theme') === 'dark' ? 'light' : 'dark';
    if (next === getSystemTheme()) localStorage.removeItem('theme');
    else localStorage.setItem('theme', next);
    applyTheme(getTheme());
  });

  colorSchemeMediaQuery.addEventListener('change', function() {
    if (!localStorage.getItem('theme')) applyTheme(getTheme());
  });
</script>

Reference: #174 (comment)


📊 Dashboard preview 📊: https://python-docs-translations.github.io/dashboard/186/merge/

Copilot AI changed the title Align theme toggle with system preference and react to prefers-color-scheme changes Align theme toggle with system preference and remove redundant normalization helper Jun 3, 2026
Copilot AI requested a review from m-aciek June 3, 2026 23:27
Copilot AI changed the title Align theme toggle with system preference and remove redundant normalization helper Refine theme toggle to use system preference by default and react to OS theme changes Jun 3, 2026
Copilot AI changed the title Refine theme toggle to use system preference by default and react to OS theme changes Clarify theme-source semantics by renaming getPreferredTheme to getSystemTheme Jun 3, 2026
@m-aciek m-aciek marked this pull request as ready for review June 3, 2026 23:46
@m-aciek m-aciek requested a review from StanFromIreland June 3, 2026 23:46
@m-aciek m-aciek changed the title Clarify theme-source semantics by renaming getPreferredTheme to getSystemTheme Align theme toggle with system preference and react to prefers-color-scheme changes Jun 3, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0ed123f91a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread templates/base.html.jinja
Copilot stopped work on behalf of m-aciek due to an error June 4, 2026 00:11
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.

2 participants