From 3f86fd0c078f889b3b3811631a56ee842ea90153 Mon Sep 17 00:00:00 2001 From: Sander Philipse <94373878+sphilipse@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:00:12 +0100 Subject: [PATCH] Search fix documents table a11y (#200232) ## 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 <42973632+kibanamachine@users.noreply.github.com> --- .../components/result/result.tsx | 1 + .../components/result/result_field.tsx | 57 ++++++++++++------- .../components/result/results_fields.tsx | 26 ++++++++- .../kbn-search-index-documents/tsconfig.json | 1 - 4 files changed, 61 insertions(+), 24 deletions(-) diff --git a/packages/kbn-search-index-documents/components/result/result.tsx b/packages/kbn-search-index-documents/components/result/result.tsx index 14b6c58ebf861..207a4770b97f2 100644 --- a/packages/kbn-search-index-documents/components/result/result.tsx +++ b/packages/kbn-search-index-documents/components/result/result.tsx @@ -121,6 +121,7 @@ export const Result: React.FC = ({ diff --git a/packages/kbn-search-index-documents/components/result/result_field.tsx b/packages/kbn-search-index-documents/components/result/result_field.tsx index e82991032afbc..acd495f71cd44 100644 --- a/packages/kbn-search-index-documents/components/result/result_field.tsx +++ b/packages/kbn-search-index-documents/components/result/result_field.tsx @@ -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'; @@ -63,26 +71,35 @@ export const ResultField: React.FC = ({ 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 ( - - - - - - - - {fieldName} - + + + + setIsPopoverOpen(!isPopoverOpen)} + iconType={iconType || (fieldType ? iconMap[fieldType] : defaultToken)} + /> + } + isOpen={isPopoverOpen} + > + {fieldTypeLabel} + + + + + {fieldName} + + + diff --git a/packages/kbn-search-index-documents/components/result/results_fields.tsx b/packages/kbn-search-index-documents/components/result/results_fields.tsx index e25ede0fe0463..9684d41d28c6b 100644 --- a/packages/kbn-search-index-documents/components/result/results_fields.tsx +++ b/packages/kbn-search-index-documents/components/result/results_fields.tsx @@ -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 = ({ fields, isExpanded }) => { +export const ResultFields: React.FC = ({ documentId, fields, isExpanded }) => { return ( - + + + + {i18n.translate('searchIndexDocuments.resultFields.fieldTypeHeaderLabel', { + defaultMessage: 'Field', + })} + + + {i18n.translate('searchIndexDocuments.resultFields.contentstableHeaderLabel', { + defaultMessage: 'Contents', + })} + + + {fields.map((field) => (