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 3 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
50 changes: 50 additions & 0 deletions src/components/highlight/__snapshots__/highlight.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,21 @@ exports[`EuiHighlight behavior loose matching matches strings with different cas

<span>
different
<span
class="euiScreenReaderOnly"
>
highlight start
</span>
<mark
class="euiMark emotion-0"
>
case
</mark>
<span
class="euiScreenReaderOnly"
>
highlight end
</span>
match
</span>
`;
Expand All @@ -26,23 +36,53 @@ exports[`EuiHighlight behavior matching applies to all matches 1`] = `
}

<span>
<span
class="euiScreenReaderOnly"
>
highlight start
</span>
<mark
class="euiMark emotion-0"
>
match
</mark>
<span
class="euiScreenReaderOnly"
>
highlight end
</span>

<span
class="euiScreenReaderOnly"
>
highlight start
</span>
<mark
class="euiMark emotion-0"
>
match
</mark>
<span
class="euiScreenReaderOnly"
>
highlight end
</span>

<span
class="euiScreenReaderOnly"
>
highlight start
</span>
<mark
class="euiMark emotion-0"
>
match
</mark>
<span
class="euiScreenReaderOnly"
>
highlight end
</span>
</span>
`;

Expand All @@ -54,11 +94,21 @@ exports[`EuiHighlight behavior matching only applies to first match 1`] = `
}

<span>
<span
class="euiScreenReaderOnly"
>
highlight start
</span>
<mark
class="euiMark emotion-0"
>
match
</mark>
<span
class="euiScreenReaderOnly"
>
highlight end
</span>
match match
</span>
`;
Expand Down
22 changes: 17 additions & 5 deletions src/components/mark/__snapshots__/mark.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiMark is rendered 1`] = `
.emotion-0 {
Array [
<span
class="euiScreenReaderOnly"
>
highlight start
</span>,
.emotion-0 {
background-color: rgba(0,119,204,0.1);
font-weight: 700;
color: #343741;
}

<mark
class="euiMark emotion-0"
>
Marked
</mark>
class="euiMark emotion-0"
>
Marked
</mark>,
<span
class="euiScreenReaderOnly"
>
highlight end
</span>,
]
`;
23 changes: 19 additions & 4 deletions src/components/mark/mark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@
* Side Public License, v 1.
*/

import React, { HTMLAttributes, FunctionComponent, ReactNode } from 'react';
import React, {
HTMLAttributes,
Fragment,
FunctionComponent,
ReactNode,
} from 'react';
import { EuiScreenReaderOnly } from '../accessibility';
import { useEuiI18n } from '../i18n';
import classNames from 'classnames';
import { CommonProps } from '../common';
import { useEuiTheme } from '../../services';
Expand All @@ -29,8 +36,16 @@ export const EuiMark: FunctionComponent<EuiMarkProps> = ({
const classes = classNames('euiMark', className);

return (
<mark css={[styles]} className={classes} {...rest}>
{children}
</mark>
<Fragment>
<EuiScreenReaderOnly>
<span>{useEuiI18n('euiMark.highlightStart', 'highlight start')}</span>
</EuiScreenReaderOnly>
<mark css={[styles]} className={classes} {...rest}>
{children}
</mark>
<EuiScreenReaderOnly>
<span>{useEuiI18n('euiMark.highlightEnd', 'highlight end')}</span>
</EuiScreenReaderOnly>
</Fragment>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2227,11 +2227,21 @@ exports[`EuiSelectableListItem props searchValue 1`] = `
class="euiSelectableListItem__text euiSelectableListItem__text--truncate"
>
<span>
<span
class="euiScreenReaderOnly"
>
highlight start
</span>
<mark
class="euiMark emotion-0"
>
Mi
</mark>
<span
class="euiScreenReaderOnly"
>
highlight end
</span>
mas
</span>
</span>
Expand Down Expand Up @@ -2428,11 +2438,21 @@ exports[`EuiSelectableListItem props searchValue 2`] = `
class="euiSelectableListItem__text euiSelectableListItem__text--truncate"
>
<span>
<span
class="euiScreenReaderOnly"
>
highlight start
</span>
<mark
class="euiMark emotion-0"
>
Mi
</mark>
<span
class="euiScreenReaderOnly"
>
highlight end
</span>
mas
</span>
</span>
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`. [(#5739)](https://github.com/elastic/eui/pull/5739)
1Copenut marked this conversation as resolved.
Show resolved Hide resolved