Skip to content

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

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

Merged
merged 4 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions BREAKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ This is a comprehensive list of the breaking changes introduced in the major ver
## Version 8.x

- [Browser and Platform Support](#version-8x-browser-platform-support)
- [Global Styles](#global-styles)
- [Dark Theme](#version-8x-dark-theme)
- [Global Styles](#version-8x-global-styles)
- [Components](#version-8x-components)
- [Button](#version-8x-button)
- [Content](#version-8x-content)
Expand Down Expand Up @@ -47,6 +48,58 @@ This section details the desktop browser, JavaScript framework, and mobile platf
| iOS | 15+ |
| Android | 5.1+ with Chromium 89+ |

<h2 id="version-8x-dark-theme">Dark Theme</h2>

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

```css
@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:

```css
/* @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:

```css
@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`](https://developer.mozilla.org/en-US/docs/Web/CSS/: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](https://ionicframework.com/docs/theming/dark-mode).

<h2 id="version-8x-global-styles">Global Styles</h2>

The `core.css` file has been updated to set the text color on the `body` element:
Expand Down Expand Up @@ -89,4 +142,4 @@ This allows components to inherit the color properly when used outside of Ionic

- `ion-picker` and `ion-picker-column` have been renamed to `ion-picker-legacy` and `ion-picker-legacy-column`, respectively. This change was made to accommodate the new inline picker component while allowing developers to continue to use the legacy picker during this migration period.
- Only the component names have been changed. Usages such as `ion-picker` or `IonPicker` should be changed to `ion-picker-legacy` and `IonPickerLegacy`, respectively.
- Non-component usages such as `pickerController` or `useIonPicker` remain unchanged. The new picker displays inline with your page content and does not have equivalents for these non-component usages.
- Non-component usages such as `pickerController` or `useIonPicker` remain unchanged. The new picker displays inline with your page content and does not have equivalents for these non-component usages.
4 changes: 2 additions & 2 deletions core/src/css/themes/dark.always.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
@include dark-base-theme();
}

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

.md body {
:root.md {
@include dark-md-theme();
}
4 changes: 2 additions & 2 deletions core/src/css/themes/dark.system.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
@include dark-base-theme();
}

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

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