Skip to content

[EuiDataGrid][A11y] Prevent duplicate screen reader output for sorted header cells #8522

Closed

Description

@mgadewoll

Description

Relates to elastic/kibana#214104

When navigating EuiDataGrid header cells with screen readers (e.g. NVDA on Windows) it will output a duplicated text for a sorted cell.

Image

This is due to the cell having both an aria-sorted attribute and an additional screenreader-only hint text linked via aria-describedby.

Image

We should check if we can remove the additional hint text. There might be reason for having it in case aria-sort might not be supported consistently across assistive technologies. This requires testing if aria-sort is output as expected by at least the main screen readers (JAWS, NVDA, VO).

Steps

  • test the sorted cell in the EuiDataGrid header in the most common SR combinations:
    • Chrome + NVDA
    • Chrome + JAWS
    • Firefox + NVDA
    • Firefox + JAWS
    • Safari + VoiceOver
  • update the conditions in packages/eui/src/components/datagrid/body/header/column_sorting.tsx
  • test the new conditions with screen readers
  • verify the SR output in Kibana > Discover

Resources

Activity

  1. added theissue type on Mar 31, 2025
  2. JasonStoltz commented on Apr 3, 2025

    @JasonStoltz
    Contributor

    We pointed this as a 3. The work itself is probably 1, but testing in different environments.

    This is based on the assumption that we can remove the additional hint text.

  3. weronikaolejniczak commented on Apr 16, 2025

    @weronikaolejniczak
    Contributor

    Testing notes

    Environment

    Using EuiDataGrid playground with sorting prop value set to:

    { "columns": [{ "id": "name", "direction": "desc" }] }

    Steps to reproduce

    1. Sort the "Name" column in descending order.
    2. Navigate with Tab to the table.
    3. Navigate with Arrow Right to the [aria-sort="descending"] column - "Name".

    Screen recordings

    Chrome + NVDA (Windows)

    Screen.Recording.2025-04-16.134559.mp4

    Chrome + JAWS (Windows)

    Audio on 🔈

    Screen.Recording.2025-04-16.140622.mp4

    Firefox + NVDA (Windows)

    Screen.Recording.2025-04-16.135155.mp4

    Firefox + JAWS (Windows)

    Audio on 🔈

    Screen.Recording.2025-04-16.140654.mp4

    Safari + VoiceOver (MacOS)

    Screen.Recording.2025-04-16.at.13.20.41.mov

    Multi-column sorting:

    Using EuiDataGrid playground with sorting prop value set to:

    { "columns": [ { "id": "name", "direction": "desc" }, { "id": "account", "direction": "asc" } ] }
    Screen.Recording.2025-04-16.at.14.32.44.mov

    Implementation context

    aria-sort

    If only one column is being sorted, the aria-sort attribute is set conditionally to indicate the sorting direction:

    /**
    * aria-sort attribute - should only be used when a single column is being sorted
    * @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-sort
    * @see https://www.w3.org/WAI/ARIA/apg/example-index/table/sortable-table.html
    * @see https://github.com/w3c/aria/issues/283 for potential future multi-column usage
    */
    const ariaSort: AriaAttributes['aria-sort'] =
    isColumnSorted && hasOnlyOneSort
    ? sorting.columns[0].direction === 'asc'
    ? 'ascending'
    : 'descending'
    : undefined;
    // aria-describedby ID for when aria-sort isn't sufficient
    const sortingAriaId = useGeneratedHtmlId({
    prefix: 'euiDataGridCellHeader',
    suffix: 'sorting',
    });

    All common screen reader + browser combinations support aria-sort announcement.

    sortingScreenReaderText

    If multiple columns are being sorted, the helper text is announced. It's rendered conditionally:

    /**
    * Sorting status - screen reader text
    */
    const sortingScreenReaderText = useMemo(() => {
    if (!isColumnSorted) return null;
    if (!hasColumnActions && hasOnlyOneSort) return null; // in this scenario, the `aria-sort` attribute will be used by screen readers
    return (

    where hasOnlyOneSort = "only one column is sorted" and !hasColumnActions means there's no context menu on the header cell:

    Image

    Proposed solution

    If we remove the !hasColumnActions from the condition in the sortingScreenReaderText, the logic will no longer consider whether column actions are available and will render the helper text always, as long as multiple columns are sorted.

    To ensure that ariaSort and sortingScreenReaderText are exclusive, we can refactor the logic to use a shared condition, e.g.:

    const useAriaSortOnly = isColumnSorted && hasOnlyOneSort;
    
    // in `ariaSort`:
    const ariaSort: AriaAttributes['aria-sort'] = useAriaSortOnly
      ? sorting.columns[0].direction === 'asc'
        ? 'ascending'
        : 'descending'
      : undefined;
    
    // in `sortingScreenReaderText`:
    if (!isColumnSorted || useAriaSortOnly) return null;
    return (
    ...

    Considerations

    Note - unfortunately this is not the case for column headers with no actions - since describedby does not work for those cells and they're using SR only text, the extra text comes along for the ride

    #6034

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions