Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions packages/eui/changelogs/upcoming/8887.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**Accessibility**

- Added accessible labels to virtualized `EuiCodeBlock`

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,27 @@ exports[`EuiCodeBlock Virtualization renders a virtualized code block 1`] = `
style="position: relative; block-size: 600px; inline-size: 600px; overflow: auto; will-change: transform; direction: ltr;"
tabindex="0"
>
<span
aria-hidden="true"
class="euiScreenReaderOnly"
data-tabular-copy-marker="no-copy"
>
✄𐘗
</span>
<div
class="emotion-euiScreenReaderOnly"
>
aria-label,
text code block:
</div>
<span
aria-hidden="true"
class="euiScreenReaderOnly"
data-tabular-copy-marker="no-copy"
>
✄𐘗
</span>
<code
aria-label="aria-label"
class="euiCodeBlock__code emotion-euiCodeBlock__code-isVirtualized"
data-code-language="text"
data-test-subj="test subject string"
Expand Down Expand Up @@ -73,6 +92,7 @@ exports[`EuiCodeBlock renders a code block 1`] = `
<div
class="emotion-euiScreenReaderOnly"
>
aria-label,
text code block:
</div>
<span
Expand All @@ -83,7 +103,6 @@ exports[`EuiCodeBlock renders a code block 1`] = `
✄𐘗
</span>
<code
aria-label="aria-label"
class="euiCodeBlock__code emotion-euiCodeBlock__code"
data-code-language="text"
data-test-subj="test subject string"
Expand Down
8 changes: 7 additions & 1 deletion packages/eui/src/components/code/code_block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const EuiCodeBlock: FunctionComponent<EuiCodeBlockProps> = ({
overflowHeight,
isVirtualized: _isVirtualized,
lineNumbers = false,
'aria-label': ariaLabel,
...rest
}) => {
const euiTheme = useEuiTheme();
Expand Down Expand Up @@ -278,7 +279,10 @@ export const EuiCodeBlock: FunctionComponent<EuiCodeBlockProps> = ({
<>
{tabularCopyMarkers.hiddenNoCopyBoundary}
<EuiScreenReaderOnly>
<div>{codeBlockLabel}</div>
<div>
{ariaLabel ? `${ariaLabel}, ` : undefined}
{codeBlockLabel}
</div>
</EuiScreenReaderOnly>
{tabularCopyMarkers.hiddenNoCopyBoundary}
</>
Expand All @@ -293,6 +297,7 @@ export const EuiCodeBlock: FunctionComponent<EuiCodeBlockProps> = ({
{isVirtualized ? (
<EuiCodeBlockVirtualized
data={data}
label={codeBlockLabelElement}
rowHeight={fontSizeToRowHeightMap[fontSize]}
overflowHeight={overflowHeight}
preProps={preProps}
Expand All @@ -314,6 +319,7 @@ export const EuiCodeBlock: FunctionComponent<EuiCodeBlockProps> = ({
{isVirtualized ? (
<EuiCodeBlockVirtualized
data={data}
label={codeBlockLabelElement}
rowHeight={fontSizeToRowHeightMap.l}
preProps={preFullscreenProps}
codeProps={codeProps}
Expand Down
13 changes: 9 additions & 4 deletions packages/eui/src/components/code/code_block_virtualized.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import React, { HTMLAttributes, forwardRef, useMemo } from 'react';
import React, { HTMLAttributes, ReactNode, forwardRef, useMemo } from 'react';
import { FixedSizeList, ListChildComponentProps } from 'react-window';
import { RefractorNode } from 'refractor';
import { logicalStyles } from '../../global_styling';
Expand All @@ -19,23 +19,28 @@ import { nodeToHtml } from './utils';

export const EuiCodeBlockVirtualized = ({
data,
label,
rowHeight,
overflowHeight,
preProps,
codeProps,
}: {
data: RefractorNode[];
label: ReactNode;
rowHeight: number;
overflowHeight?: number | string;
preProps: HTMLAttributes<HTMLPreElement>;
codeProps: HTMLAttributes<HTMLElement>;
}) => {
const VirtualizedOuterElement = useMemo(
() =>
forwardRef<any, any>(({ style, ...props }, ref) => (
<pre style={logicalStyles(style)} {...props} ref={ref} {...preProps} />
forwardRef<any, any>(({ style, children, ...props }, ref) => (
<pre style={logicalStyles(style)} {...props} ref={ref} {...preProps}>
{label}
{children}
</pre>
)),
[preProps]
[preProps, label]
);

const VirtualizedInnerElement = useMemo(
Expand Down