mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-09 08:09:32 +08:00
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:
@ -13,6 +13,7 @@ html.md {
|
||||
}
|
||||
|
||||
html {
|
||||
--ion-default-dynamic-font: -apple-system-body;
|
||||
--ion-font-family: var(--ion-default-font);
|
||||
}
|
||||
|
||||
|
||||
35
core/src/css/test/a11y/typography.e2e.ts
Normal file
35
core/src/css/test/a11y/typography.e2e.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { expect } from '@playwright/test';
|
||||
import { configs, test } from '@utils/test/playwright';
|
||||
|
||||
configs({ directions: ['ltr'], modes: ['ios'] }).forEach(({ title, screenshot, config }) => {
|
||||
test.describe(title('typography: font scaling'), () => {
|
||||
test('should scale text on larger font sizes', async ({ page }) => {
|
||||
await page.setContent(
|
||||
`
|
||||
<style>
|
||||
html {
|
||||
font-size: 310%;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div>
|
||||
<h1>Heading 1</h1>
|
||||
<h2>Heading 2</h2>
|
||||
<h3>Heading 3</h3>
|
||||
<h4>Heading 4</h4>
|
||||
<h5>Heading 5</h5>
|
||||
<h6>Heading 6</h6>
|
||||
<p>
|
||||
The quick brown fox <ion-text><sup>jumps</sup></ion-text> over the <ion-text><sub>lazy dog</sub></ion-text>
|
||||
</p>
|
||||
</div>
|
||||
`,
|
||||
config
|
||||
);
|
||||
|
||||
const div = page.locator('div');
|
||||
|
||||
await expect(div).toHaveScreenshot(screenshot(`typography-scale`));
|
||||
});
|
||||
});
|
||||
});
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 56 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 52 KiB |
@ -11,27 +11,40 @@ $headings-font-weight: 500 !default;
|
||||
$headings-line-height: 1.2 !default;
|
||||
|
||||
/// @prop - Font size of heading level 1
|
||||
$h1-font-size: 26px !default;
|
||||
$h1-font-size: dynamic-font(26px) !default;
|
||||
|
||||
/// @prop - Font size of heading level 2
|
||||
$h2-font-size: 24px !default;
|
||||
$h2-font-size: dynamic-font(24px) !default;
|
||||
|
||||
/// @prop - Font size of heading level 3
|
||||
$h3-font-size: 22px !default;
|
||||
$h3-font-size: dynamic-font(22px) !default;
|
||||
|
||||
/// @prop - Font size of heading level 4
|
||||
$h4-font-size: 20px !default;
|
||||
$h4-font-size: dynamic-font(20px) !default;
|
||||
|
||||
/// @prop - Font size of heading level 5
|
||||
$h5-font-size: 18px !default;
|
||||
$h5-font-size: dynamic-font(18px) !default;
|
||||
|
||||
/// @prop - Font size of heading level 6
|
||||
$h6-font-size: 16px !default;
|
||||
$h6-font-size: dynamic-font(16px) !default;
|
||||
|
||||
html {
|
||||
font-family: var(--ion-font-family);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dynamic Type is an iOS-only feature, so
|
||||
* this should only be enabled on iOS devices.
|
||||
*/
|
||||
@supports (-webkit-touch-callout: none) {
|
||||
html {
|
||||
/**
|
||||
* Includes fallback if Dynamic Type is not enabled.
|
||||
*/
|
||||
font: var(--ion-dynamic-font, 16px var(--ion-font-family));
|
||||
}
|
||||
}
|
||||
|
||||
a {
|
||||
background-color: transparent;
|
||||
color: ion-color(primary, base);
|
||||
|
||||
Reference in New Issue
Block a user