Skip to content

Add Dark Mode and Theme Toggle Support to Trac - #309

Open
kehach07 wants to merge 10 commits into
django:mainfrom
kehach07:darkmode
Open

kehach07 wants to merge 10 commits into
django:mainfrom
kehach07:darkmode

Conversation

@kehach07

Copy link
Copy Markdown
Contributor

Summary

This draft PR introduces dark mode support and theme toggle functionality to Django's Trac instance (code.djangoproject.com), aligning its design, color tokens, and toggle behavior with the main djangoproject.com website.

Work done under Google Summer of Code (GSoC) 2026 with the Django Software Foundation.


Key Changes

  • Theme Toggle Component: Implemented a 3-state switcher (Auto $\rightarrow$ Light $\rightarrow$ Dark) matching the upstream toggle behavior on the main Django website.
  • Template Updates: Updated trac-env/templates/site_header.html and site_head.html to inject theme markup, include accessibility hooks, and load dark mode scripts.
  • Stylesheets & Tokens: Created scss/trachacks.scss and darkmode.css with clean CSS custom properties for surfaces, borders, ticket tables, query builders, and admin views.
  • Accessibility Enhancements: Added accessible labels (aria-label, visible focus outlines, and compliant .visually-hidden styling) and fixed contrast ratios across key pages.
  • Dev Workflow & Docs: Updated README.rst and docker-entrypoint.sh for smoother static asset builds and local plugin registration checks.

Testing & Verification

  • Verified theme switching and state persistence across page refreshes.
  • Confirmed support for system preference detection (prefers-color-scheme).
  • Tested keyboard accessibility and screen-reader announcements using Accessibility Insights for Web.
  • Verified views locally across /query, /ticket, and /admin.

Related Links & References

- Improve contrast for query count (.numrows) and inline filter buttons
- Fix text and link contrast for breadcrumbs (#pagepath) and search buttons
- Enhance admin sidebar navigation (#tabs) active states and subheadings
- Correct contrast for missing/forbidden indicators in table rows

@sabderemane sabderemane left a comment

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.

Hey @kehach07 ! This is close! It's missing the last changes and we are good to go ⭐

If there are anything else after that, I think it could be fixed in another PR while this one is merged.

Comment thread trac-env/htdocs/css/darkmode.css Resolved
Comment thread trac-env/htdocs/css/darkmode.css Resolved
Comment thread trac-env/htdocs/css/darkmode.css Resolved
Comment thread trac-env/htdocs/css/darkmode.css Resolved
…de blocks

- Ensure readable dark text on foldable pill buttons and hover states
- Standardize muted text and alternate format links to #9f9d9d
- Improve ticket code blocks and timeline/comment indicators

@jacobtylerwalls jacobtylerwalls left a comment

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.

Thanks for waiting so patiently for a review @kehach07!

I'm looking forward to trying this out. (I was on a plane recently, and the cabin lights were dimmed. Upon opening my laptop, Trac happened to be open, and the light mode burned the retinas of everyone around me, so this will definitely be a welcome improvement!)

I did a preliminary smoke test and had a couple questions. I'd like to look at the code a little more closely, but I'm glad to see @sabderemane has already done a through review. 🙌

Comment thread docker-entrypoint.sh Resolved
Comment thread trac-env/htdocs/css/darkmode.css Resolved
Comment thread trac-env/htdocs/css/darkmode.css Resolved
@jacobtylerwalls

This comment was marked as resolved.

@kehach07

This comment was marked as resolved.

- Improve code block background and diff table contrast in dark mode
- Respect user Pygments syntax themes without token override collisions
- Remove redundant tracdjangoplugin installation check in entrypoint script

@jacobtylerwalls jacobtylerwalls left a comment

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.

Thanks for the updates @kehach07! These are my last comments, and then my plan is to deploy your branch to the preview server.

A few last contrast issues I noticed below. (If you can't easily find the steps to navigate to these pages, just say so and I'll provide step-by-step notes.)

I marked a couple as "minor" that I would be comfortable "futuring". @sabderemane if you think there are some more we should bounce to a new ticket, let me know, I don't want to extend the scope of this project unreasonably 👍


Both modes:

  • When focused, button text:
Image

Light mode:

  • When focused, the text "-" inside the icon on the filter removal button
Image

Dark mode:

  • Comment preview box (see gray text, also dark mode ignored)
Image
  • Highlighted text in input fields:
Image
  • Search result titles (blue on black):
Image
  • Search result highlighting after selecting a result (ticket page) (gray on yellow):
Image
  • The inline diff toggle appears reversed -- this screenshot shows the "tabular" view, but it looks like "unified" has more emphasis
Image
  • [minor:] Ticket confirmation banner: ticket number before "has been created"
Image
  • [minor:] "Paste an image to attach"
Image

Comment thread trac-env/htdocs/css/darkmode.css Outdated
========================================================================== */
/* ==========================================================================
1. Light Theme & Base Scope
Fixes Jacob's "light gray on beige" issue in light mode

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.

You don't need to refer to me in the file :-)

Comment thread trac-env/htdocs/css/darkmode.css Outdated

html[data-theme="dark"] #tabs,
html[data-theme="dark"] div#tabs,
@media (prefers-color-scheme: dark) {

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.

My IDE highlights this as invalid syntax ("selector expected"). I don't think a media query can follow a list of selectors.

There are a couple others in this file (are they dead code?)

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 agree, selectors should be inside the media query or a separate rule identical to the media query, so they both applies the same thing. I guess the rule is skipped in that case yeah 🤔

@sabderemane

Copy link
Copy Markdown
Member

@jacobtylerwalls makes sense to me, any new thing spotted could be a new ticket, so we can merge this work, it would be a good addition first ⭐

@jacobtylerwalls

jacobtylerwalls commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

@kehach07 @sabderemane

I put these changes on the preview branch (plus some cosmetic edits) as shown here.

You can check https://code.preview.djangoproject.com/
I'll mention the password in Discord.

I noticed the dark mode switcher JS file is missing, though. So I'll look into how this project's asset pipeline needs adjusting. Until then you can check it by adding data-theme="dark" to the <html> tag in dev tools. EDIT: fixed by committing the file

@kehach07

Copy link
Copy Markdown
Contributor Author

@kehach07 @sabderemane

I put these changes on the preview branch (plus some cosmetic edits) as shown here.

You can check https://code.preview.djangoproject.com/ I'll mention the password in Discord.

I noticed the dark mode switcher JS file is missing, though. So I'll look into how this project's asset pipeline needs adjusting. Until then you can check it by adding data-theme="dark" to the <html> tag in dev tools. EDIT: fixed by committing the file

Thanks for the feedback! I’ll check the preview and work on fixing the issues. Appreciate your help!

@kehach07

Copy link
Copy Markdown
Contributor Author

Hi @jacobtylerwalls, I've pushed the latest changes in edfe56f covering all the contrast and CSS issues we discussed. Please let me know if anything else needs attention!

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.

3 participants