Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CSS-in-JS] Convert EuiScreenReaderOnly #5846

Merged
merged 20 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src-docs/src/views/accessibility/styles_helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';

import {
EuiCode,
euiScreenReaderOnlyStyles,
euiScreenReaderOnly,
EuiText,
useEuiFocusRing,
} from '../../../../src';
Expand Down Expand Up @@ -34,7 +34,7 @@ export default () => {
snippet={'<p className="euiScreenReaderOnly" />'}
/>
<ThemeExample
title={<code>euiScreenReaderOnlyStyles()</code>}
title={<code>euiScreenReaderOnly()</code>}
description={
<p>
This function allows you to apply the screen reader only CSS styles
Expand All @@ -44,12 +44,12 @@ export default () => {
example={
<EuiText size="s">
<p>The next paragraph is hidden except for screen readers.</p>
<p css={css(euiScreenReaderOnlyStyles())}>
<p css={css(euiScreenReaderOnly())}>
I am hidden except for screen readers
</p>
</EuiText>
}
snippet={'<p css={css(euiScreenReaderOnlyStyles())} />'}
snippet={'<p css={css(euiScreenReaderOnly())} />'}
/>
<ThemeExample
title={<code>useEuiFocusRing(offset?, color?)</code>}
Expand Down
1 change: 1 addition & 0 deletions src/components/accessibility/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export { EuiScreenReaderLive } from './screen_reader_live';
export type { EuiScreenReaderLiveProps } from './screen_reader_live';
export {
EuiScreenReaderOnly,
euiScreenReaderOnly,
euiScreenReaderOnlyStyles,
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
} from './screen_reader_only';
export type { EuiScreenReaderOnlyProps } from './screen_reader_only';
Expand Down
5 changes: 4 additions & 1 deletion src/components/accessibility/screen_reader_only/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@

export type { EuiScreenReaderOnlyProps } from './screen_reader_only';
export { EuiScreenReaderOnly } from './screen_reader_only';
export { euiScreenReaderOnlyStyles } from './screen_reader_only.styles';
export {
euiScreenReaderOnly,
euiScreenReaderOnlyStyles,
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
} from './screen_reader_only.styles';
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import { css } from '@emotion/react';

const euiScreenReaderOnly = `
const euiScreenReaderOnlyStatic = `
position: absolute;
left: -10000px;
top: auto;
Expand All @@ -17,14 +17,22 @@ const euiScreenReaderOnly = `
overflow: hidden;
`;

/*
* Mixin
*/
export const euiScreenReaderOnly = () => euiScreenReaderOnlyStatic;

/*
* Styles
*/
export const euiScreenReaderOnlyStyles = (showOnFocus?: boolean) => {
if (showOnFocus) {
return css`
// The :active selector is necessary for Safari which removes :focus when a button is pressed
&:not(:focus):not(:active) {
${euiScreenReaderOnly}
${euiScreenReaderOnlyStatic}
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
}
`;
}
return css(euiScreenReaderOnly);
return css(euiScreenReaderOnlyStatic);
};