diff --git a/src-docs/src/views/accessibility/screen_reader_styles.tsx b/src-docs/src/views/accessibility/screen_reader_styles.tsx index 58c687a617cf..7211e995980e 100644 --- a/src-docs/src/views/accessibility/screen_reader_styles.tsx +++ b/src-docs/src/views/accessibility/screen_reader_styles.tsx @@ -1,12 +1,12 @@ import { css } from '@emotion/react'; import React from 'react'; -import { EuiText, euiScreenReaderOnlyStyles } from '../../../../src'; +import { EuiText, euiScreenReaderOnly } from '../../../../src'; export default () => (

This is the first paragraph. It is visible to all.

-

+

This is the second paragraph. It is hidden for sighted users but visible to screen readers.

diff --git a/src-docs/src/views/accessibility/styles_helpers.tsx b/src-docs/src/views/accessibility/styles_helpers.tsx index 75841b9e8bb2..b3650851eaa3 100644 --- a/src-docs/src/views/accessibility/styles_helpers.tsx +++ b/src-docs/src/views/accessibility/styles_helpers.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { EuiCode, - euiScreenReaderOnlyStyles, + euiScreenReaderOnly, EuiText, useEuiFocusRing, } from '../../../../src'; @@ -17,6 +17,7 @@ export default () => { <> .euiScreenReaderOnly} + type="className" description={

This utility class allows you to apply the screen reader only CSS @@ -34,7 +35,8 @@ export default () => { snippet={'

'} /> euiScreenReaderOnlyStyles()} + title={euiScreenReaderOnly()} + type="function" description={

This function allows you to apply the screen reader only CSS styles @@ -44,15 +46,21 @@ export default () => { example={

The next paragraph is hidden except for screen readers.

-

+

I am hidden except for screen readers

} - snippet={'

'} + snippetLanguage="emotion" + snippet={'${euiScreenReaderOnly()}'} /> useEuiFocusRing(offset?, color?)} + type="hook" description={

By default, all interactable elements will inherit the{' '} diff --git a/src/components/accessibility/index.ts b/src/components/accessibility/index.ts index 13eb07bda066..12a82997e7b2 100644 --- a/src/components/accessibility/index.ts +++ b/src/components/accessibility/index.ts @@ -8,10 +8,7 @@ export { EuiScreenReaderLive } from './screen_reader_live'; export type { EuiScreenReaderLiveProps } from './screen_reader_live'; -export { - EuiScreenReaderOnly, - euiScreenReaderOnlyStyles, -} from './screen_reader_only'; +export { EuiScreenReaderOnly, euiScreenReaderOnly } from './screen_reader_only'; export type { EuiScreenReaderOnlyProps } from './screen_reader_only'; export { EuiSkipLink } from './skip_link'; export type { EuiSkipLinkProps } from './skip_link'; diff --git a/src/components/accessibility/screen_reader_only/index.ts b/src/components/accessibility/screen_reader_only/index.ts index ed6a7e6ac09b..a041c1fa905d 100644 --- a/src/components/accessibility/screen_reader_only/index.ts +++ b/src/components/accessibility/screen_reader_only/index.ts @@ -8,4 +8,4 @@ export type { EuiScreenReaderOnlyProps } from './screen_reader_only'; export { EuiScreenReaderOnly } from './screen_reader_only'; -export { euiScreenReaderOnlyStyles } from './screen_reader_only.styles'; +export { euiScreenReaderOnly } from './screen_reader_only.styles'; diff --git a/src/components/accessibility/screen_reader_only/screen_reader_only.styles.ts b/src/components/accessibility/screen_reader_only/screen_reader_only.styles.ts index e6b07360fdda..59668a924798 100644 --- a/src/components/accessibility/screen_reader_only/screen_reader_only.styles.ts +++ b/src/components/accessibility/screen_reader_only/screen_reader_only.styles.ts @@ -6,15 +6,25 @@ * Side Public License, v 1. */ -import { css } from '@emotion/react'; - -export const euiScreenReaderOnlyStyles = () => { - return css` - position: absolute; - left: -10000px; - top: auto; - width: 1px; - height: 1px; - overflow: hidden; - `; -}; +/* + * Mixin that hides elements offscreen to only be read by screen reader + * See https://github.com/elastic/eui/pull/5130 and https://github.com/elastic/eui/pull/5152 for more info + */ +export const euiScreenReaderOnly = () => ` + // Take the element out of the layout + position: absolute; + // Keep it vertically inline + top: auto; + // Chrome requires a left value, and Selenium (used by Kibana's FTR) requires an off-screen position for its .getVisibleText() to not register SR-only text + left: -10000px; + // The element must have a size (for some screen readers) + width: 1px; + height: 1px; + // But reduce the visible size to nothing + clip: rect(0 0 0 0); + clip-path: inset(50%); + // And ensure no overflows occur + overflow: hidden; + // Chrome requires the negative margin to not cause overflows of parent containers + margin: -1px; +`; diff --git a/src/components/highlight/__snapshots__/highlight.test.tsx.snap b/src/components/highlight/__snapshots__/highlight.test.tsx.snap index c9d562a876e9..59055f04cf33 100644 --- a/src/components/highlight/__snapshots__/highlight.test.tsx.snap +++ b/src/components/highlight/__snapshots__/highlight.test.tsx.snap @@ -4,7 +4,7 @@ exports[`EuiHighlight behavior loose matching matches strings with different cas different case @@ -15,19 +15,19 @@ exports[`EuiHighlight behavior loose matching matches strings with different cas exports[`EuiHighlight behavior matching applies to all matches 1`] = ` match match match @@ -59,7 +59,7 @@ exports[`EuiHighlight behavior matching hasScreenReaderHelpText can be false 1`] exports[`EuiHighlight behavior matching only applies to first match 1`] = ` match diff --git a/src/components/mark/__snapshots__/mark.test.tsx.snap b/src/components/mark/__snapshots__/mark.test.tsx.snap index fb20f8a40aa7..bba41820b79e 100644 --- a/src/components/mark/__snapshots__/mark.test.tsx.snap +++ b/src/components/mark/__snapshots__/mark.test.tsx.snap @@ -3,7 +3,7 @@ exports[`EuiMark is rendered 1`] = ` Marked diff --git a/src/components/mark/mark.styles.ts b/src/components/mark/mark.styles.ts index 0de0a80f2d92..57b2f67e506d 100644 --- a/src/components/mark/mark.styles.ts +++ b/src/components/mark/mark.styles.ts @@ -8,6 +8,7 @@ import { css } from '@emotion/react'; import { UseEuiTheme, transparentize } from '../../services'; +import { euiScreenReaderOnly } from '../accessibility'; export const euiMarkStyles = ( { euiTheme, colorMode }: UseEuiTheme, @@ -39,13 +40,7 @@ export const euiMarkStyles = ( ` &:before, &:after { - clip-path: inset(100%); - clip: rect(1px, 1px, 1px, 1px); - height: 1px; - overflow: hidden; - position: absolute; - white-space: nowrap; - width: 1px; + ${euiScreenReaderOnly()} } &:before { diff --git a/src/components/selectable/selectable_list/__snapshots__/selectable_list.test.tsx.snap b/src/components/selectable/selectable_list/__snapshots__/selectable_list.test.tsx.snap index 0ddda377ce4d..cb8164fdf1cd 100644 --- a/src/components/selectable/selectable_list/__snapshots__/selectable_list.test.tsx.snap +++ b/src/components/selectable/selectable_list/__snapshots__/selectable_list.test.tsx.snap @@ -2222,7 +2222,7 @@ exports[`EuiSelectableListItem props searchValue 1`] = ` > Mi @@ -2417,7 +2417,7 @@ exports[`EuiSelectableListItem props searchValue 2`] = ` > Mi diff --git a/upcoming_changelogs/5921.md b/upcoming_changelogs/5921.md new file mode 100644 index 000000000000..22ec3f74ab8a --- /dev/null +++ b/upcoming_changelogs/5921.md @@ -0,0 +1,7 @@ +**Bug fixes** + +- Fixed `EuiMark`'s screen reader helpers causing scroll issues in Chrome + +**CSS-in-JS conversions** + +- Renamed `euiScreenReaderOnlyStyles()` mixin to `euiScreenReaderOnly()`