Skip to content

fix(playground): apply the dark palette to demos in dark mode - #4905

Open
thetaPC wants to merge 3 commits into
mainfrom
demo-dark-palette
Open

thetaPC wants to merge 3 commits into
mainfrom
demo-dark-palette

Conversation

@thetaPC

@thetaPC thetaPC commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Demos stopped following the site's dark mode when Ionic renamed ion-theme-dark to ion-palette-dark. Updating the class alone leaves them half dark, because common.js loaded the palette before ionic.bundle.css and the bundle's default colors won.

  • common.js toggles ion-palette-dark and loads the palette right after ionic.bundle.css, the order an app uses. Demos that load their own palette, like the theming demos, are skipped.
  • The datetime global theming and preference-based animation demos target .ion-palette-dark instead of body.dark, which nothing sets.

Visible change: demos now go dark with the site, and the Dark Mode page's class demos switch palette along with their toggle.

How to test

Switch the preview to dark mode:

@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ionic-docs Ready Ready Preview Dec 1, 2026 5:13pm UTC

Request Review

@thetaPC
thetaPC marked this pull request as ready for review December 1, 2026 23:28
@thetaPC
thetaPC requested a review from a team as a code owner December 1, 2026 23:28
@thetaPC
thetaPC requested a review from brandyscarney December 1, 2026 23:28

@brandyscarney brandyscarney 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.

Great fix, thank you!

Comment thread static/usage/v8/common.js
linkElement.rel = 'stylesheet';
linkElement.href = 'https://cdn.jsdelivr.net/npm/@ionic/core@8/css/palettes/dark.class.css';

document.querySelector('link[href*="ionic.bundle.css"]').after(linkElement);

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.

If a demo ever leaves out the ionic.bundle.css link, this throws. Because it runs in the same DOMContentLoaded callback as the message listener and console capture, that demo would also stop following the site theme and lose its console. Every current demo has the link, so this is just hardening. Could we fall back to appending it to the head?

const bundle = document.querySelector('link[href*="ionic.bundle.css"]');
bundle ? bundle.after(linkElement) : document.head.append(linkElement);

Same for v9.

This branch was successfully deployed

1 active deployment
Preview — 2a546625 Deployed Dec 1, 2026 by vercel[bot]
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