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>
This commit is contained in:
Liam DeBeasi
2023-10-10 17:38:09 -04:00
committed by GitHub
parent 57e2476370
commit f8067819ee
546 changed files with 2364 additions and 396 deletions

View File

@ -24,20 +24,6 @@
letter-spacing: #{$button-ios-letter-spacing};
}
/**
* The default buttons in a toolbar
* have a different font size/weight
* than buttons outside of a toolbar on iOS.
* However, we still want the "size"/"strong"
* properties to be usable in a toolbar, so we add
* the .in-buttons selector such that we
* can add the different font size/weight in a toolbar
* but still let "size"/"strong" override it.
*/
:host(.in-buttons) {
font-size: #{$toolbar-ios-button-font-size};
font-weight: 400;
}
// iOS Solid Button
// --------------------------------------------------
@ -82,6 +68,25 @@
}
// iOS Toolbar Buttons
// --------------------------------------------------
/**
* The default buttons in a toolbar
* have a different font size/weight
* than buttons outside of a toolbar on iOS.
* However, we still want the "size"/"strong"
* properties to be usable in a toolbar, so we add
* the .in-buttons selector such that we
* can add the different font size/weight in a toolbar
* but still let "size"/"strong" override it.
*/
:host(.in-buttons) {
font-size: #{$toolbar-ios-button-font-size};
font-weight: 400;
}
// iOS Button Sizes
// --------------------------------------------------
@ -127,7 +132,7 @@
}
// iOS strong Button
// iOS Strong Button
// --------------------------------------------------
:host(.button-strong) {

View File

@ -34,7 +34,9 @@ $button-ios-min-height: 3.1em !default;
$button-ios-border-radius: 14px !default;
/// @prop - Font size of the button text
$button-ios-font-size: 16px !default;
/// The maximum font size is calculated by taking the default font size
/// and multiplying it by 3, since 310% of the default is the maximum
$button-ios-font-size: dynamic-font-max(16px, 3) !default;
/// @prop - Font weight of the button text
$button-ios-font-weight: 500 !default;
@ -83,7 +85,9 @@ $button-ios-large-min-height: 3.1em !default;
$button-ios-large-border-radius: 16px !default;
/// @prop - Font size of the large button
$button-ios-large-font-size: 20px !default;
/// The maximum font size is calculated by taking the default font size
/// and multiplying it by 3, since 310% of the default is the maximum
$button-ios-large-font-size: dynamic-font-max(20px, 3) !default;
// iOS Small Button
@ -108,7 +112,9 @@ $button-ios-small-min-height: 2.1em !default;
$button-ios-small-border-radius: 6px !default;
/// @prop - Font size of the small button
$button-ios-small-font-size: 13px !default;
/// The maximum font size is calculated by taking the default font size
/// and multiplying it by 3, since 310% of the default is the maximum
$button-ios-small-font-size: dynamic-font-max(13px, 3) !default;
// iOS Outline Button
@ -151,13 +157,15 @@ $button-ios-outline-background-color-focused: ion-color(primary, base, $
// --------------------------------------------------
/// @prop - Font size of the clear button
$button-ios-clear-font-size: 17px !default;
/// The maximum font size is calculated by taking the default font size
/// and multiplying it by 3, since 310% of the default is the maximum
$button-ios-clear-font-size: dynamic-font-max(17px, 3) !default;
/// @prop - Font weight of the clear button
$button-ios-clear-font-weight: normal !default;
/// @prop - Letter spacing of the button
$button-ios-letter-spacing: 0 !default;
$button-ios-letter-spacing: 0 !default;
/// @prop - Border color of the clear button
$button-ios-clear-border-color: transparent !default;

View File

@ -34,7 +34,7 @@ $button-md-min-height: 36px !default;
$button-md-border-radius: 4px !default;
/// @prop - Font size of the button text
$button-md-font-size: 14px !default;
$button-md-font-size: dynamic-font(14px) !default;
/// @prop - Font weight of the button text
$button-md-font-weight: 500 !default;
@ -78,7 +78,7 @@ $button-md-large-padding-start: $button-md-large-padding
$button-md-large-min-height: 2.8em !default;
/// @prop - Font size of the large button
$button-md-large-font-size: 20px !default;
$button-md-large-font-size: dynamic-font(20px) !default;
// Material Design Small Button
@ -100,7 +100,7 @@ $button-md-small-padding-start: $button-md-small-padding
$button-md-small-min-height: 2.1em !default;
/// @prop - Font size of the small button
$button-md-small-font-size: 13px !default;
$button-md-small-font-size: dynamic-font(13px) !default;
// Material Design Outline Button

View File

@ -0,0 +1,82 @@
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';
configs({ directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
test.describe(title('button: font scaling'), () => {
test('should scale default button text on larger font sizes', async ({ page }) => {
await page.setContent(
`
<style>
html {
font-size: 310%;
}
</style>
<ion-button>Default</ion-button>
`,
config
);
const button = page.locator('ion-button');
await expect(button).toHaveScreenshot(screenshot(`button-default-scale`));
});
test('should scale clear button text on larger font sizes', async ({ page }) => {
await page.setContent(
`
<style>
html {
font-size: 310%;
}
</style>
<ion-button fill="clear">Clear</ion-button>
`,
config
);
const button = page.locator('ion-button');
await expect(button).toHaveScreenshot(screenshot(`button-clear-scale`));
});
test('should scale small button text on larger font sizes', async ({ page }) => {
await page.setContent(
`
<style>
html {
font-size: 310%;
}
</style>
<ion-button size="small">Small</ion-button>
`,
config
);
const button = page.locator('ion-button');
await expect(button).toHaveScreenshot(screenshot(`button-small-scale`));
});
test('should scale large button text on larger font sizes', async ({ page }) => {
await page.setContent(
`
<style>
html {
font-size: 310%;
}
</style>
<ion-button size="large">Large</ion-button>
`,
config
);
const button = page.locator('ion-button');
await expect(button).toHaveScreenshot(screenshot(`button-large-scale`));
});
});
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB