diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx index af501c4be44..857654a3218 100644 --- a/.storybook/preview.tsx +++ b/.storybook/preview.tsx @@ -48,7 +48,10 @@ import { hideStorybookControls } from './utils'; const preview: Preview = { decorators: [ (Story, context) => ( - +
{ /> + + + We strongly recommend using relative (rem or{' '} + em) units instead of px when + possible{' '} + + } + > +

+ Relative font units respect configured browser default font sizes, + which some users may set to larger than than the 16px default due to, + e.g. visual impairment, monitor size, or personal preference.{' '} + + Read more on accessible text resizing. + +

+
tableLayout="auto" diff --git a/src/components/provider/provider.stories.tsx b/src/components/provider/provider.stories.tsx new file mode 100644 index 00000000000..7eb59fe5767 --- /dev/null +++ b/src/components/provider/provider.stories.tsx @@ -0,0 +1,43 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import React from 'react'; +import type { Meta, StoryObj } from '@storybook/react'; + +import { EuiProvider, EuiProviderProps } from './provider'; + +const meta: Meta> = { + title: 'EuiProvider', + component: EuiProvider, + argTypes: { + colorMode: { + control: 'select', + options: ['light', 'dark', 'inverse', 'LIGHT', 'DARK', 'INVERSE'], + }, + modify: { control: 'object' }, + componentDefaults: { control: 'object' }, + globalStyles: { control: 'boolean' }, + utilityClasses: { control: 'boolean' }, + }, +}; + +export default meta; +type Story = StoryObj>; + +export const FontDefaultUnits: Story = { + render: () => ( + <> + Change `modify.font.defaultUnits` to{' '} + `rem`, `em`, or `px` and then inspect this demo's `html` + CSS + + ), + args: { + modify: { font: { defaultUnits: 'rem' } }, + }, +}; diff --git a/src/global_styling/reset/global_styles.tsx b/src/global_styling/reset/global_styles.tsx index f485bd0199c..55cd8d5cc2c 100644 --- a/src/global_styling/reset/global_styles.tsx +++ b/src/global_styling/reset/global_styles.tsx @@ -37,12 +37,15 @@ export const EuiGlobalStyles = ({}: EuiGlobalStylesProps) => { * This font reset sets all our base font/typography related properties * that are needed to override browser-specific element settings. */ - const fontReset = ` - font-family: ${font.family}; - font-size: ${`${font.scale[font.body.scale] * base}px`}; - line-height: ${base / (font.scale[font.body.scale] * base)}; - font-weight: ${font.weight[font.body.weight]}; - `; + const fontBodyScale = font.scale[font.body.scale]; + const fontReset = { + fontFamily: font.family, + fontSize: `${ + font.defaultUnits === 'px' ? fontBodyScale * base : fontBodyScale + }${font.defaultUnits}`, + lineHeight: base / (fontBodyScale * base), + fontWeight: font.weight[font.body.weight], + }; /** * Final styles @@ -70,7 +73,10 @@ export const EuiGlobalStyles = ({}: EuiGlobalStylesProps) => { input, textarea, select { - ${fontReset} + ${{ + ...fontReset, + fontSize: '1rem', // Inherit from html root + }} } // Chrome has opinionated select:disabled opacity styles that need to be overridden diff --git a/upcoming_changelogs/7182.md b/upcoming_changelogs/7182.md new file mode 100644 index 00000000000..aa34dd7ed82 --- /dev/null +++ b/upcoming_changelogs/7182.md @@ -0,0 +1,7 @@ +**Breaking changes** + +- EUI's global body font-size now respects the `font.defaultUnits` token. This means that the global font size will use the `rem` unit by default, instead of `px`. + +**Accessibility** + +- When using `rem` or `em` font units, EUI now respects, instead of ignoring, browser default font sizes set by end users.