diff --git a/src/components/accessibility/screen_reader_only/__snapshots__/screen_reader_only.test.tsx.snap b/src/components/accessibility/screen_reader_only/__snapshots__/screen_reader_only.test.tsx.snap index b96c8872fdc..c6f851ca209 100644 --- a/src/components/accessibility/screen_reader_only/__snapshots__/screen_reader_only.test.tsx.snap +++ b/src/components/accessibility/screen_reader_only/__snapshots__/screen_reader_only.test.tsx.snap @@ -18,7 +18,7 @@ exports[`EuiScreenReaderOnly adds an accessibility class to a child element when exports[`EuiScreenReaderOnly will show on focus 1`] = ` Link 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 5099dea3540..9ef1131029c 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 @@ -34,13 +34,13 @@ export const euiScreenReaderOnly = () => ` /* * Styles */ -export const euiScreenReaderOnlyStyles = (showOnFocus?: boolean) => ({ - euiScreenReaderOnly: showOnFocus - ? css` - /* The :active selector is necessary for Safari which removes :focus when a button is pressed */ - &:not(:focus, :active, :focus-within) { - ${euiScreenReaderOnly()} - } - ` - : css(euiScreenReaderOnly()), -}); +export const euiScreenReaderOnlyStyles = { + euiScreenReaderOnly: css(euiScreenReaderOnly()), + + 'euiScreenReaderOnly-showOnFocus': css` + /* The :active selector is necessary for Safari which removes :focus when a button is pressed */ + &:not(:focus, :active, :focus-within) { + ${euiScreenReaderOnly()} + } + `, +}; diff --git a/src/components/accessibility/screen_reader_only/screen_reader_only.tsx b/src/components/accessibility/screen_reader_only/screen_reader_only.tsx index e46e5278db6..426e627c2c0 100644 --- a/src/components/accessibility/screen_reader_only/screen_reader_only.tsx +++ b/src/components/accessibility/screen_reader_only/screen_reader_only.tsx @@ -6,11 +6,11 @@ * Side Public License, v 1. */ -import { ReactElement, FunctionComponent } from 'react'; +import { ReactElement, FunctionComponent, useMemo } from 'react'; import classNames from 'classnames'; import { cloneElementWithCss } from '../../../services'; -import { euiScreenReaderOnlyStyles } from './screen_reader_only.styles'; +import { euiScreenReaderOnlyStyles as styles } from './screen_reader_only.styles'; export interface EuiScreenReaderOnlyProps { /** @@ -30,13 +30,15 @@ export const EuiScreenReaderOnly: FunctionComponent< > = ({ children, className, showOnFocus }) => { const classes = classNames(className, children.props.className); - const styles = euiScreenReaderOnlyStyles(showOnFocus); - const cssStyles = [styles.euiScreenReaderOnly]; - - const props = { - className: classes.length ? classes : undefined, - css: cssStyles, - }; + const props = useMemo( + () => ({ + className: classes.length ? classes : undefined, + css: showOnFocus + ? styles['euiScreenReaderOnly-showOnFocus'] + : styles.euiScreenReaderOnly, + }), + [classes, showOnFocus] + ); return cloneElementWithCss(children, props); }; diff --git a/src/components/accessibility/skip_link/__snapshots__/skip_link.test.tsx.snap b/src/components/accessibility/skip_link/__snapshots__/skip_link.test.tsx.snap index 4106e4460c1..866b85be69e 100644 --- a/src/components/accessibility/skip_link/__snapshots__/skip_link.test.tsx.snap +++ b/src/components/accessibility/skip_link/__snapshots__/skip_link.test.tsx.snap @@ -3,7 +3,7 @@ exports[`EuiSkipLink is rendered 1`] = ` @@ -34,7 +34,7 @@ exports[`EuiSkipLink props position absolute is rendered 1`] = ` exports[`EuiSkipLink props position fixed is rendered 1`] = ` @@ -59,7 +59,7 @@ exports[`EuiSkipLink props position static is rendered 1`] = ` exports[`EuiSkipLink props tabIndex is rendered 1`] = ` = ({ onClick: _onClick, ...rest }) => { - const euiTheme = useEuiTheme(); - const styles = euiSkipLinkStyles(euiTheme); - const classes = classNames('euiSkipLink', className); + const styles = useEuiMemoizedStyles(euiSkipLinkStyles); const cssStyles = [ styles.euiSkipLink, position !== 'static' ? styles[position] : undefined, diff --git a/src/components/aspect_ratio/__snapshots__/aspect_ratio.test.tsx.snap b/src/components/aspect_ratio/__snapshots__/aspect_ratio.test.tsx.snap index 023e07b1663..4a4909315da 100644 --- a/src/components/aspect_ratio/__snapshots__/aspect_ratio.test.tsx.snap +++ b/src/components/aspect_ratio/__snapshots__/aspect_ratio.test.tsx.snap @@ -1,46 +1,15 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`EuiAspectRatio allows overriding with custom styles 1`] = ` -