Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A a11yproject.com
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 40
    • Issues 40
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 10
    • Merge requests 10
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • The A11Y Project
  • a11yproject.com
  • Merge requests
  • !1423

Implement base JS and markup for a theme toggle

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/Andy-set-studio/theme-toggle into main Mar 14, 2022
  • Overview 4
  • Commits 2
  • Pipelines 0
  • Changes 4

Created by: Andy-set-studio

This addition adds a markup pattern—radio buttons—and some lightweight JavaScript that gets and sets a user-color-scheme localStorage value based on their state.

This state is then applied in two places:

  1. As a data-user-theme value on the HTML root element
  2. As a checked state on the corresponding radio button control

Every time this state changes, the data is saved in localStorage. When a page is loaded with the apply-theme-setting.min.js script in the <head> before the CSS is loaded, the correct theme via localStorage will be applied.

The default theme is system. The intent of that is that the user’s preference will be honoured.

A browser with dev tools showing the radio buttons and the user-color-scheme attribute on the html root. Arrows and boxes demonstrate the relationship.

I've added a temporary page that features the new HTML controls. This is to hopefully make your lives easier when it comes to applying the CSS.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/Andy-set-studio/theme-toggle