Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(themes): modify the dark themes to use :root for mode-specific styles #28833

Merged
merged 4 commits into from
Jan 19, 2024

Conversation

brandyscarney
Copy link
Member

@brandyscarney brandyscarney commented Jan 15, 2024

Issue number: N/A


What is the current behavior?

The system and always dark theme files target the mode-specific styles by using the following selectors:

:root {
  @include dark-base-theme();
}

.ios body {
  @include dark-ios-theme();
}

.md body {
  @include dark-md-theme();
}

This is an issue because then users cannot override the dark theme by targeting :root.ios, they must target the body.

What is the new behavior?

Updates the mode selectors to target the :root with the mode-specific class:

:root {
  @include dark-base-theme();
}

:root.ios {
  @include dark-ios-theme();
}

:root.md {
  @include dark-md-theme();
}

This makes more sense, since we want it to still be global but mode-specific, and allows users to override it on :root if desired.

Does this introduce a breaking change?

  • Yes
  • Maybe
  • No

BREAKING CHANGES:

In previous versions, it was recommended to define the dark theme in the following way:

@media (prefers-color-scheme: dark) {
  body {
    /* global app variables */
  }

  .ios body {
    /* global ios app variables */
  }

  .md body {
    /* global md app variables */
  }
}

In Ionic Framework version 8, the dark theme is being distributed via css files that can be imported. Below is an example of importing a dark theme file in Angular:

/* @import '@ionic/angular/css/themes/dark.always.css'; */
/* @import "@ionic/angular/css/themes/dark.class.css"; */
@import "@ionic/angular/css/themes/dark.system.css";

By importing the dark.system.css file, the dark theme variables will be defined like the following:

@media (prefers-color-scheme: dark) {
  :root {
    /* global app variables */
  }

  :root.ios {
    /* global ios app variables */
  }

  :root.md {
    /* global md app variables */
  }
}

Notice that the dark theme is now applied to the :root selector instead of the body selector. The :root selector represents the <html> element and is identical to the selector html, except that its specificity is higher.

While migrating to include the new dark theme files is unlikely to cause breaking changes, these new selectors can lead to unexpected overrides if custom CSS variables are being set on the body element. We recommend updating any instances where global application variables are set to target the :root selector instead.

For more information on the new dark theme files, refer to the Dark Mode documentation.

Other Information

Dev build: 7.6.2-dev.11705355381.14b22962

@github-actions github-actions bot added the package: core @ionic/core package label Jan 15, 2024
@brandyscarney brandyscarney marked this pull request as ready for review January 16, 2024 15:26
@brandyscarney brandyscarney requested review from a team and liamdebeasi and removed request for a team January 16, 2024 15:36
@brandyscarney brandyscarney requested a review from a team as a code owner January 18, 2024 22:38
@brandyscarney brandyscarney merged commit a8e1e16 into feature-8.0 Jan 19, 2024
44 checks passed
@brandyscarney brandyscarney deleted the bc/fix-dark-theme-exports branch January 19, 2024 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: core @ionic/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants