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

Added internationalized screen reader helpers to EuiMark. #5739

Merged
merged 14 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
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
60 changes: 60 additions & 0 deletions src/components/highlight/__snapshots__/highlight.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ exports[`EuiHighlight behavior loose matching matches strings with different cas
color: #343741;
}

.emotion-0:before,
.emotion-0:after {
-webkit-clip-path: inset(100%);
clip-path: inset(100%);
cli: rect(1px, 1px, 1px, 1px);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}

.emotion-0:before {
content: ' [highlight start] ';
}

.emotion-0:after {
content: ' [highlight end] ';
}

<span>
different
<mark
Expand All @@ -25,6 +45,26 @@ exports[`EuiHighlight behavior matching applies to all matches 1`] = `
color: #343741;
}

.emotion-0:before,
.emotion-0:after {
-webkit-clip-path: inset(100%);
clip-path: inset(100%);
cli: rect(1px, 1px, 1px, 1px);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}

.emotion-0:before {
content: ' [highlight start] ';
}

.emotion-0:after {
content: ' [highlight end] ';
}

<span>
<mark
class="euiMark emotion-0"
Expand Down Expand Up @@ -53,6 +93,26 @@ exports[`EuiHighlight behavior matching only applies to first match 1`] = `
color: #343741;
}

.emotion-0:before,
.emotion-0:after {
-webkit-clip-path: inset(100%);
clip-path: inset(100%);
cli: rect(1px, 1px, 1px, 1px);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}

.emotion-0:before {
content: ' [highlight start] ';
}

.emotion-0:after {
content: ' [highlight end] ';
}

<span>
<mark
class="euiMark emotion-0"
Expand Down
20 changes: 20 additions & 0 deletions src/components/mark/__snapshots__/mark.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ exports[`EuiMark is rendered 1`] = `
color: #343741;
}

.emotion-0:before,
.emotion-0:after {
-webkit-clip-path: inset(100%);
clip-path: inset(100%);
cli: rect(1px, 1px, 1px, 1px);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}

.emotion-0:before {
content: ' [highlight start] ';
}

.emotion-0:after {
content: ' [highlight end] ';
}

<mark
class="euiMark emotion-0"
>
Expand Down
11 changes: 11 additions & 0 deletions src/components/mark/mark.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,16 @@ export const euiMarkStyles = ({ euiTheme, colorMode }: UseEuiTheme) => {
// Override the browser's black color.
// Can't use 'inherit' because the text to background color contrast may not be sufficient
color: ${euiTheme.colors.text};

&:before,
&:after {
clip-path: inset(100%);
cli: rect(1px, 1px, 1px, 1px);
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}
`;
};
18 changes: 17 additions & 1 deletion src/components/mark/mark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/

import React, { HTMLAttributes, FunctionComponent, ReactNode } from 'react';
import { css } from '@emotion/react';
import { useEuiI18n } from '../i18n';
import classNames from 'classnames';
import { CommonProps } from '../common';
import { useEuiTheme } from '../../services';
Expand All @@ -27,9 +29,23 @@ export const EuiMark: FunctionComponent<EuiMarkProps> = ({
const useTheme = useEuiTheme();
const styles = euiMarkStyles(useTheme);
thompsongl marked this conversation as resolved.
Show resolved Hide resolved
const classes = classNames('euiMark', className);
const highlightStart = useEuiI18n(
'euiMark.highlightStart',
'highlight start'
);
const highlightEnd = useEuiI18n('euiMark.highlightEnd', 'highlight end');
const pseudoStyles = css`
&:before {
content: ' [${highlightStart}] ';
}

&:after {
content: ' [${highlightEnd}] ';
}
`;

return (
<mark css={[styles]} className={classes} {...rest}>
<mark css={[styles, pseudoStyles]} className={classes} {...rest}>
{children}
</mark>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2133,6 +2133,26 @@ exports[`EuiSelectableListItem props searchValue 1`] = `
color: #343741;
}

.emotion-0:before,
.emotion-0:after {
-webkit-clip-path: inset(100%);
clip-path: inset(100%);
cli: rect(1px, 1px, 1px, 1px);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}

.emotion-0:before {
content: ' [highlight start] ';
}

.emotion-0:after {
content: ' [highlight end] ';
}

<div
class="euiSelectableList testClass1 testClass2"
data-test-subj="test subject string"
Expand Down Expand Up @@ -2334,6 +2354,26 @@ exports[`EuiSelectableListItem props searchValue 2`] = `
color: #343741;
}

.emotion-0:before,
.emotion-0:after {
-webkit-clip-path: inset(100%);
clip-path: inset(100%);
cli: rect(1px, 1px, 1px, 1px);
height: 1px;
overflow: hidden;
position: absolute;
white-space: nowrap;
width: 1px;
}

.emotion-0:before {
content: ' [highlight start] ';
}

.emotion-0:after {
content: ' [highlight end] ';
}

<div
class="euiSelectableList testClass1 testClass2"
data-test-subj="test subject string"
Expand Down
1 change: 1 addition & 0 deletions upcoming_changelogs/5739.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Added internationalized screen reader helpers to `EuiMark`