Skip to content

Commit

Permalink
Search fix documents table a11y (elastic#200232)
Browse files Browse the repository at this point in the history
## Summary

This improves the accessibility of the documents table by:
1. Adding header rows with titles
2. Adding an accessible table description
3. Adding an accessible popover to the field type icon

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
2 people authored and jesuswr committed Nov 18, 2024
1 parent 01e03fd commit 3f86fd0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const Result: React.FC<ResultProps> = ({
<EuiHorizontalRule margin="none" />
<EuiSplitPanel.Inner paddingSize="m">
<ResultFields
documentId={metaData.id}
isExpanded={isExpanded}
fields={isExpanded ? fields : fields.slice(0, defaultVisibleFields)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import React from 'react';
import React, { useState } from 'react';

import { EuiTableRow, EuiTableRowCell, EuiText, EuiToken } from '@elastic/eui';
import {
EuiButtonIcon,
EuiFlexGroup,
EuiFlexItem,
EuiPopover,
EuiTableRow,
EuiTableRowCell,
EuiText,
} from '@elastic/eui';

import { euiThemeVars } from '@kbn/ui-theme';
import { i18n } from '@kbn/i18n';
import { ResultFieldProps } from './result_types';
import { PERMANENTLY_TRUNCATED_FIELDS } from './constants';
import { ResultFieldValue } from './result_field_value';
Expand Down Expand Up @@ -63,26 +71,35 @@ export const ResultField: React.FC<ResultFieldProps> = ({
isExpanded,
}) => {
const shouldTruncate = !isExpanded || PERMANENTLY_TRUNCATED_FIELDS.includes(fieldType);
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const fieldTypeLabel = i18n.translate('searchIndexDocuments.result.fieldTypeAriaLabel', {
defaultMessage: 'This field is of the type {fieldType}',
values: { fieldType },
});

return (
<EuiTableRow className="resultField">
<EuiTableRowCell className="resultFieldRowCell" width={euiThemeVars.euiSizeL} valign="middle">
<span>
<EuiToken
className="resultField__token"
iconType={iconType || (fieldType ? iconMap[fieldType] : defaultToken)}
/>
</span>
</EuiTableRowCell>
<EuiTableRowCell
className="resultFieldRowCell"
width="20%"
truncateText={!isExpanded}
valign="middle"
>
<EuiText size="s" color="default">
{fieldName}
</EuiText>
<EuiTableRowCell className="resultFieldRowCell" valign="middle" truncateText={!isExpanded}>
<EuiFlexGroup direction="row" alignItems="center" gutterSize="xs" justifyContent="center">
<EuiFlexItem grow={false}>
<EuiPopover
button={
<EuiButtonIcon
onClick={() => setIsPopoverOpen(!isPopoverOpen)}
iconType={iconType || (fieldType ? iconMap[fieldType] : defaultToken)}
/>
}
isOpen={isPopoverOpen}
>
{fieldTypeLabel}
</EuiPopover>
</EuiFlexItem>
<EuiFlexItem>
<EuiText size="s" color="default">
{fieldName}
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</EuiTableRowCell>
<EuiTableRowCell className="resultFieldRowCell" truncateText={shouldTruncate} valign="middle">
<ResultFieldValue fieldValue={fieldValue} fieldType={fieldType} isExpanded={isExpanded} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,39 @@

import React from 'react';

import { EuiTable, EuiTableBody } from '@elastic/eui';
import { EuiTable, EuiTableBody, EuiTableHeader, EuiTableHeaderCell } from '@elastic/eui';

import { i18n } from '@kbn/i18n';
import { ResultField } from './result_field';
import { ResultFieldProps } from './result_types';

interface Props {
documentId: string;
fields: ResultFieldProps[];
isExpanded: boolean;
}

export const ResultFields: React.FC<Props> = ({ fields, isExpanded }) => {
export const ResultFields: React.FC<Props> = ({ documentId, fields, isExpanded }) => {
return (
<EuiTable>
<EuiTable
aria-label={i18n.translate('searchIndexDocuments.resultFields.tableLabel', {
defaultMessage: 'Fields for the document with ID {documentId}',
values: { documentId },
})}
>
<EuiTableHeader>
<EuiTableHeaderCell width="20%">
{i18n.translate('searchIndexDocuments.resultFields.fieldTypeHeaderLabel', {
defaultMessage: 'Field',
})}
</EuiTableHeaderCell>
<EuiTableHeaderCell>
{i18n.translate('searchIndexDocuments.resultFields.contentstableHeaderLabel', {
defaultMessage: 'Contents',
})}
</EuiTableHeaderCell>
</EuiTableHeader>

<EuiTableBody>
{fields.map((field) => (
<ResultField
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-search-index-documents/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"kbn_references": [
"@kbn/i18n",
"@kbn/i18n-react",
"@kbn/ui-theme",
"@kbn/core",
"@kbn/core-elasticsearch-server",
]
Expand Down

0 comments on commit 3f86fd0

Please sign in to comment.