Skip to content
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
51d3849
docs(high-contrast): add first pass
liamdebeasi Feb 5, 2024
c03b24b
docs: add always playground
liamdebeasi Feb 5, 2024
066a161
typos
liamdebeasi Feb 5, 2024
26d1c49
docs: add to sidebar
liamdebeasi Feb 5, 2024
cee93a2
docs(high-contrast): add system docs
liamdebeasi Feb 5, 2024
12504b0
content clean up
liamdebeasi Feb 5, 2024
028cc3f
content changes
liamdebeasi Feb 5, 2024
35f01f8
add overview, clean up
liamdebeasi Feb 6, 2024
759eb86
chore: clean up
liamdebeasi Feb 6, 2024
4e22fca
chore: clean up
liamdebeasi Feb 6, 2024
f48f7fe
fix imports
liamdebeasi Feb 6, 2024
3b19c23
add class demo
liamdebeasi Feb 6, 2024
70f6314
lint
liamdebeasi Feb 6, 2024
3e3009f
a word
liamdebeasi Feb 6, 2024
ba11cf3
Update high-contrast-mode.md
liamdebeasi Feb 6, 2024
715de6f
add color=“light”
liamdebeasi Feb 6, 2024
ad007e3
update packagejson
liamdebeasi Feb 6, 2024
8f76445
remove commented out files
liamdebeasi Feb 6, 2024
e569314
Update docs/theming/high-contrast-mode.md
liamdebeasi Feb 9, 2024
ea4cfea
Update docs/theming/high-contrast-mode.md
liamdebeasi Feb 9, 2024
baa16e7
note dark mode for high contrast system
liamdebeasi Feb 9, 2024
5d62e64
Update docs/theming/high-contrast-mode.md
liamdebeasi Feb 9, 2024
65b2433
Update docs/theming/high-contrast-mode.md
liamdebeasi Feb 9, 2024
8b1b0fe
fix vue typo
liamdebeasi Feb 9, 2024
895624e
note why we are importing both light and dark themes
liamdebeasi Feb 9, 2024
e462370
show how to import dark always theme
liamdebeasi Feb 9, 2024
bcafcbe
remove extra code
liamdebeasi Feb 9, 2024
484db1b
clean up
liamdebeasi Feb 9, 2024
90ca840
avoid custom titles to avoid linter
liamdebeasi Feb 9, 2024
e46374c
lint
liamdebeasi Feb 9, 2024
31ca911
note default behavior
liamdebeasi Feb 9, 2024
851d6f7
clarify
liamdebeasi Feb 9, 2024
daadec0
clarify customization options
liamdebeasi Feb 12, 2024
3d246bb
Update docs/theming/high-contrast-mode.md
liamdebeasi Feb 12, 2024
025151c
typo
liamdebeasi Feb 12, 2024
225dc62
use css class terminology
liamdebeasi Feb 12, 2024
c27e062
use css term
liamdebeasi Feb 12, 2024
eea4903
another typo
liamdebeasi Feb 12, 2024
5b70e28
consistent links
liamdebeasi Feb 12, 2024
7e623d6
css
liamdebeasi Feb 12, 2024
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
1 change: 1 addition & 0 deletions cspell-wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Swiper
Udemy
Vetur
Wistia
WCAG

actionsheet
fabs
Expand Down
228 changes: 228 additions & 0 deletions docs/theming/high-contrast-mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
---
title: Hide Contrast Mode
initialTab: 'preview'
inlineHtmlPreviews: true
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<head>
<title>High Contrast Mode to Increase Color Contrast</title>
<meta
name="description"
content="Developers are adding high contrast mode CSS on native applications to support their user preferences. Read to learn more about high contrast color schemes for Ionic apps."
/>
</head>

Ionic ships with themes for increased contrast for users with low vision. These themes work by increasing the contrast between foreground content, such as text, and background content, such as UI components. Ionic provides light and dark variants for high contrast.

## Overview

The [Ionic colors](./colors) in the high contrast theme have been updated to meet [Level AAA color contrast](https://www.w3.org/WAI/WCAG21/Understanding/contrast-enhanced.html) as defined by the Web Content Accessibility Guidelines (WCAG) when used with the appropriate contrast color. The theme also seeks to improve the contrast of UI components such as the border on an Item. However, Ionic's high contrast theme prioritizes text. This means that if increasing the contrast of a UI component against the page background would significantly reduce the contrast of the component's text against the component's background, the UI component contrast will not be modified.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not super clear, so open to ideas for how to better explain this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Courtesy of Chat GPT:

"The Ionic high contrast theme has been enhanced to adhere to Level AAA color contrast standards as outlined in the Web Content Accessibility Guidelines (WCAG), particularly when paired with the appropriate contrast color. Notably, improvements have been made to the contrast of UI components, including item borders. However, it's important to note that within the high contrast theme, priority is given to text legibility. Consequently, if adjusting the contrast of a UI component against the background would significantly compromise the contrast between the component's text and its background, the contrast of the UI component will remain unchanged."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to combine in 851d6f7. Lmk your thoughts


## Enabling High Contrast Theme

There are three provided ways to enable the high contrast theme in an app: **always**, based on **system** settings, or by using a **class**.

### Always

The default theme provided with Ionic Framework also uses the default color contrast levels. The high contrast theme can be enabled by importing the following stylesheet in the appropriate files. This approach will enable the high contrast theme regardless of a user's preference for high contrast.

<Tabs groupId="framework" defaultValue="angular" values={[{ value: 'angular', label: 'Angular' }, { value: 'javascript', label: 'Javascript' }, { value: 'react', label: 'React' }, { value: 'vue', label: 'Vue' }]}>

<TabItem value="angular">

```css
@import '@ionic/angular/css/themes/high-contrast.always.css';
```

</TabItem>
<TabItem value="javascript">

```ts
import '@ionic/core/css/themes/high-contrast.always.css';
```

</TabItem>
<TabItem value="react">

```tsx
import '@ionic/react/css/themes/high-contrast.always.css';
```

</TabItem>
<TabItem value="vue">

```ts
import '@ionic/vue/css/themes/high-contrast.always.css';
```

</TabItem>

</Tabs>

The high contrast dark theme can be applied by importing `high-contrast-dark.always.css` instead of `high-contrast.always.css`.

The following example will always display the high contrast light theme, regardless of the user's preference for high contrast or dark mode.

import AlwaysHighContrastMode from '@site/static/usage/v8/theming/always-high-contrast-mode/index.md';

<AlwaysHighContrastMode />

### System

The system approach to enabling high contrast mode involves checking the system settings for the user's preferred contrast. This is the default when starting a new Ionic Framework app. Importing the following stylesheets in the appropriate file will automatically retrieve the user's preference from the system settings and apply the high contrast theme when high contrast is preferred.

<Tabs groupId="framework" defaultValue="angular" values={[{ value: 'angular', label: 'Angular' }, { value: 'javascript', label: 'Javascript' }, { value: 'react', label: 'React' }, { value: 'vue', label: 'Vue' }]}>

<TabItem value="angular">

```css
@import '@ionic/angular/css/themes/high-contrast.system.css';
@import '@ionic/angular/css/themes/high-contrast-dark.system.css';
```

</TabItem>
<TabItem value="javascript">

```ts
import '@ionic/core/css/themes/high-contrast.system.css';
import '@ionic/core/css/themes/high-contrast-dark.system.css';
```

</TabItem>
<TabItem value="react">

```tsx
import '@ionic/react/css/themes/high-contrast.system.css';
import '@ionic/react/css/themes/high-contrast-dark.system.css';
```

</TabItem>
<TabItem value="vue">

```ts
import '@ionic/vue/css/themes/high-contrast.system.css';
import '@ionic/vue/css/themes/high-contrast-dark.system.css';
```

</TabItem>

</Tabs>

This approach activates the high contrast theme when the [CSS media query for `prefers-contrast`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-contrast) is `more`. The `prefers-contrast` media query is supported by [all modern browsers](https://caniuse.com/?search=prefers-contrast). If support for an older browser is required, we recommend using the [class](#class) approach.

The following example uses the system settings to decide when to show high contrast mode.

:::info
Not sure how to change the system settings? Here's how to enable high contrast mode on [Windows 11](hhttps://support.microsoft.com/en-us/windows/turn-high-contrast-mode-on-or-off-in-windows-909e9d89-a0f9-a3a9-b993-7a6dcee85025) and on [macOS](https://support.apple.com/guide/mac-help/change-display-settings-for-accessibility-unac089/mac).
:::

import SystemHighContrastMode from '@site/static/usage/v8/theming/system-high-contrast-mode/index.md';

<SystemHighContrastMode />
:::caution The high contrast light theme must be imported after [core.css](../layout/global-stylesheets#corecss), and the
high contrast dark theme must be imported after `dark.system.css`. Otherwise, the standard contrast theme will take priority.
:::

### Class

While the previous approaches are excellent for enabling the high contrast theme through file imports alone, there are scenarios where you may need more control over its application. In cases where you need to apply the high contrast theme conditionally, such as through a toggle, or if you want to extend the functionality based on system settings, we provide a high contrast theme class file. This file applies the high contrast theme when a specific class is added to an app. Importing the following stylesheets into the appropriate file will provide the necessary styles for using the high contrast theme with the class:

<Tabs groupId="framework" defaultValue="angular" values={[{ value: 'angular', label: 'Angular' }, { value: 'javascript', label: 'Javascript' }, { value: 'react', label: 'React' }, { value: 'vue', label: 'Vue' }]}>

<TabItem value="angular">

```css
@import '@ionic/angular/css/themes/high-contrast.class.css';
@import '@ionic/angular/css/themes/high-contrast-dark.class.css';
```

</TabItem>
<TabItem value="javascript">

```ts
import '@ionic/core/css/themes/high-contrast.class.css';
import '@ionic/core/css/themes/high-contrast-dark.class.css';
```

</TabItem>
<TabItem value="react">

```tsx
import '@ionic/react/css/themes/high-contrast.class.css';
import '@ionic/react/css/themes/high-contrast-dark.class.css';
```

</TabItem>
<TabItem value="vue">

```ts
import '@ionic/vue/css/themes/high-contrast.class.css';
import '@ionic/vue/css/themes/high-contrast-dark.class.css';
```

</TabItem>

</Tabs>

This approach activates the high contrast theme when the `.ion-theme-high-contrast` class is set on the `html` element. This class must be applied by the developer. This can be combined with the [`.ion-theme-dark` class](./dark-mode#class) to conditionally apply the high contrast dark theme.

The following example combines site settings, system settings, and the toggle to decide when to show high contrast mode. The site's theme takes precedence over system settings. If your system settings differ from the site's theme when the demo loads, it will use the site's theme.

:::info
Not sure how to change the system settings? Here's how to enable high contrast mode on [Windows 11](hhttps://support.microsoft.com/en-us/windows/turn-high-contrast-mode-on-or-off-in-windows-909e9d89-a0f9-a3a9-b993-7a6dcee85025) and on [macOS](https://support.apple.com/guide/mac-help/change-display-settings-for-accessibility-unac089/mac).
:::

import ClassHighContrastMode from '@site/static/usage/v8/theming/class-high-contrast-mode/index.md';

<ClassHighContrastMode />
:::caution Important The high contrast light theme must be imported after [core.css](../layout/global-stylesheets#corecss),
and the high contrast dark theme must be imported after `dark.class.css`. Otherwise, the standard contrast theme will take
priority. :::

:::caution Important
The `.ion-theme-high-contrast` class **must** be added to the `html` element in order to work with the imported high contrast theme.
:::

## Customizing Ionic High Contrast Theme

Ionic has a recommended high contrast theme that can be enabled in three different ways: [always](#always), based on [system](#system) settings, or by using a [class](#class). Each of these methods involves importing the high contrast theme file with the corresponding name.

The theme variables are set by importing the relevant high contrast theme file and do not need to be copied into an app. For more information on the variables being changed, including additional variables for further customization, refer to the [Themes](themes.md) section.

<Tabs groupId="darkFiles" defaultValue="always" values={[{ value: 'always', label: 'Always (high-contrast.always.css)' }, { value: 'system', label: 'System (high-contrast.system.css)' }, { value: 'class', label: 'Class (high-contrast.class.css)' }]}>

<TabItem value="always">

The **always** high contrast theme behaves in the following ways:

1. Sets the [Ionic colors](colors.md) for all [modes](platform-styles.md#ionic-modes) to complement a high contrast theme in the `:root` selector. The [`:root`](https://developer.mozilla.org/en-US/docs/Web/CSS/:root) selector is identical to the selector `html`, except that its [specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity) is higher.
2. Setting variables for the high contrast theme on `ios` devices using the `:root.ios` selector.
3. Setting variables for the high contrast theme on `md` devices using the `:root.md` selector.

</TabItem>

<TabItem value="system">

The **system** high contrast theme behaves in the following ways:

1. Sets the [Ionic colors](colors.md) for all [modes](platform-styles.md#ionic-modes) to complement a high contrast theme in the `:root` selector. The [`:root`](https://developer.mozilla.org/en-US/docs/Web/CSS/:root) selector is identical to the selector `html`, except that its [specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity) is higher.
2. Setting variables for the high contrast theme on `ios` devices using the `:root.ios` selector.
3. Setting variables for the high contrast theme on `md` devices using the `:root.md` selector.
4. Only applies these variables when the [CSS media query for `prefers-contrast`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-contrast) is `more`.

</TabItem>

<TabItem value="class">

The **class** high contrast theme behaves in the following ways:

1. Sets the [Ionic colors](colors.md) for all [modes](platform-styles.md#ionic-modes) to complement a high contrast theme in the `.ion-theme-high-contrast` selector. The `.ion-theme-high-contrast` class must be added to the `html` element in an app.
2. Setting variables for the high contrast theme on `ios` devices using the `.ion-theme-high-contrast.ios` selector.
3. Setting variables for the high contrast theme on `md` devices using the `.ion-theme-high-contrast.md` selector.

</TabItem>

</Tabs>
1 change: 1 addition & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ module.exports = {
'theming/colors',
'theming/themes',
'theming/dark-mode',
'theming/high-contrast-mode',
'theming/advanced',
'theming/color-generator',
],
Expand Down
4 changes: 2 additions & 2 deletions static/code/stackblitz/v8/angular/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"@ionic/angular": "7.6.2-dev.11705355381.14b22962",
"@ionic/core": "7.6.2-dev.11705355381.14b22962",
"@ionic/angular": "7.6.7-dev.11707162903.1706e75f",
"@ionic/core": "7.6.7-dev.11707162903.1706e75f",
"@angular/platform-browser-dynamic": "17.0.4"
}
}
2 changes: 1 addition & 1 deletion static/code/stackblitz/v8/html/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"dependencies": {
"@ionic/core": "7.6.2-dev.11705355381.14b22962"
"@ionic/core": "7.6.7-dev.11707162903.1706e75f"
}
}
68 changes: 34 additions & 34 deletions static/code/stackblitz/v8/react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading