feat(a11y): add dynamic font scaling (#28314)
Issue number: resolves #24638, resolves #18592 --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> Developers have requested that Ionic Framework support the dynamic type feature on iOS for accessibility purposes. Ionic applications do not respond to font scaling on iOS which can create inaccessible applications particularly for users with low vision. Ionic apps on Android devices currently support the Android equivalent due to functionality in the Chromium webview. Developers have also requested a way of adjusting the fonts in their Ionic UI components consistently. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Ionic components now use `rem` instead of `px` where appropriate. This means devs can change the font size on `html` and the text in supported Ionic components will scale up/down appropriately - Add support for Dynamic Type on iOS (the iOS version of Dynamic Font Scaling) ## Does this introduce a breaking change? - [ ] Yes - [x] No <!-- If this introduces a breaking change, please describe the impact and migration path for existing applications below. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> --------- Co-authored-by: Maria Hutt <thetaPC@users.noreply.github.com> Co-authored-by: Brandy Carney <brandyscarney@users.noreply.github.com> Co-authored-by: Shawn Taylor <shawn@ionic.io> Co-authored-by: ionitron <hi@ionicframework.com> Co-authored-by: Sean Perkins <sean@ionic.io> Co-authored-by: Sean Perkins <13732623+sean-perkins@users.noreply.github.com> Co-authored-by: Amanda Johnston <90629384+amandaejohnston@users.noreply.github.com>
@ -16,7 +16,7 @@
|
||||
:host(.label-stacked) {
|
||||
@include margin(null, null, 4px, null);
|
||||
|
||||
font-size: 14px;
|
||||
font-size: dynamic-font(14px);
|
||||
}
|
||||
|
||||
:host(.label-floating) {
|
||||
@ -48,14 +48,14 @@
|
||||
::slotted(*) h1 {
|
||||
@include margin(3px, 0, 2px);
|
||||
|
||||
font-size: 22px;
|
||||
font-size: dynamic-font(22px);
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
::slotted(*) h2 {
|
||||
@include margin(0, 0, 2px);
|
||||
|
||||
font-size: 17px;
|
||||
font-size: dynamic-font(17px);
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@
|
||||
::slotted(*) h6 {
|
||||
@include margin(0, 0, 3px);
|
||||
|
||||
font-size: 14px;
|
||||
font-size: dynamic-font(14px);
|
||||
font-weight: normal;
|
||||
|
||||
line-height: normal;
|
||||
|
||||
@ -23,7 +23,7 @@ $label-ios-margin-bottom: $item-ios-padding-bottom !default;
|
||||
$label-ios-margin-start: 0 !default;
|
||||
|
||||
/// @prop - Font size of the label when the text wraps
|
||||
$label-ios-text-wrap-font-size: 14px !default;
|
||||
$label-ios-text-wrap-font-size: dynamic-font(14px) !default;
|
||||
|
||||
/// @prop - Line height of the label when the text wraps
|
||||
$label-ios-text-wrap-line-height: 1.5 !default;
|
||||
|
||||
@ -148,14 +148,14 @@
|
||||
::slotted(*) h1 {
|
||||
@include margin(0, 0, 2px);
|
||||
|
||||
font-size: 24px;
|
||||
font-size: dynamic-font(24px);
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
::slotted(*) h2 {
|
||||
@include margin(2px, 0);
|
||||
|
||||
font-size: 16px;
|
||||
font-size: dynamic-font(16px);
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@
|
||||
::slotted(*) h6 {
|
||||
@include margin(2px, 0);
|
||||
|
||||
font-size: 14px;
|
||||
font-size: dynamic-font(14px);
|
||||
font-weight: normal;
|
||||
|
||||
line-height: normal;
|
||||
@ -174,9 +174,9 @@
|
||||
::slotted(*) p {
|
||||
@include margin(0, 0, 2px);
|
||||
|
||||
font-size: 14px;
|
||||
font-size: dynamic-font(14px);
|
||||
|
||||
line-height: 20px;
|
||||
line-height: dynamic-font(20px);
|
||||
|
||||
text-overflow: inherit;
|
||||
|
||||
|
||||
84
core/src/components/label/test/a11y/label.e2e.ts
Normal file
@ -0,0 +1,84 @@
|
||||
import { expect } from '@playwright/test';
|
||||
import { configs, test } from '@utils/test/playwright';
|
||||
|
||||
configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
|
||||
test.describe(title('label: font scaling'), () => {
|
||||
test('should scale text on larger font sizes', async ({ page }) => {
|
||||
await page.setContent(
|
||||
`
|
||||
<style>
|
||||
html {
|
||||
font-size: 310%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<ion-label>Label</ion-label>
|
||||
`,
|
||||
config
|
||||
);
|
||||
|
||||
const label = page.locator('ion-label');
|
||||
|
||||
await expect(label).toHaveScreenshot(screenshot(`label-scale`));
|
||||
});
|
||||
test('should scale text on larger font sizes when wrapping', async ({ page }) => {
|
||||
await page.setContent(
|
||||
`
|
||||
<style>
|
||||
html {
|
||||
font-size: 310%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<ion-label class="ion-text-wrap">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</ion-label>
|
||||
`,
|
||||
config
|
||||
);
|
||||
|
||||
const label = page.locator('ion-label');
|
||||
|
||||
await expect(label).toHaveScreenshot(screenshot(`label-wrap-scale`));
|
||||
});
|
||||
test('should scale text on larger font sizes when label contains headings and paragraphs', async ({ page }) => {
|
||||
await page.setContent(
|
||||
`
|
||||
<style>
|
||||
html {
|
||||
font-size: 310%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<ion-label>
|
||||
<h1>Heading 1</h1>
|
||||
<h2>Heading 2</h2>
|
||||
<h3>Heading 3</h3>
|
||||
<p>Paragraph</p>
|
||||
</ion-label>
|
||||
`,
|
||||
config
|
||||
);
|
||||
|
||||
const label = page.locator('ion-label');
|
||||
|
||||
await expect(label).toHaveScreenshot(screenshot(`label-headings-scale`));
|
||||
});
|
||||
test('should scale text on larger font sizes when position is stacked', async ({ page }) => {
|
||||
await page.setContent(
|
||||
`
|
||||
<style>
|
||||
html {
|
||||
font-size: 310%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<ion-label position="stacked">Stacked</ion-label>
|
||||
`,
|
||||
config
|
||||
);
|
||||
|
||||
const label = page.locator('ion-label');
|
||||
|
||||
await expect(label).toHaveScreenshot(screenshot(`label-stacked-scale`));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 21 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 19 KiB |
|
After Width: | Height: | Size: 20 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 2.4 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 3.9 KiB |
|
After Width: | Height: | Size: 3.7 KiB |
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 32 KiB |
|
After Width: | Height: | Size: 44 KiB |
|
After Width: | Height: | Size: 50 KiB |
|
After Width: | Height: | Size: 38 KiB |