Skip to content

Commit

Permalink
pkg/lib: Give empty "Th" elements a aria-label attribute
Browse files Browse the repository at this point in the history
As requested by this warning:

    Th: Table headers must have an accessible name. If the Th is
    intended to be visually empty, pass in screenReaderText. If the Th
    contains only non-text, interactive content such as a checkbox or
    expand toggle, pass in an aria-label.
  • Loading branch information
mvollmer committed May 10, 2024
1 parent 935aef1 commit c027d89
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pkg/lib/cockpit-components-table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* along with Cockpit; If not, see <http://www.gnu.org/licenses/>.
*/

import cockpit from 'cockpit';

import React, { useState, useEffect } from 'react';
import {
ExpandableRowContent,
Expand All @@ -28,6 +30,8 @@ import { Text, TextContent, TextVariants } from "@patternfly/react-core/dist/esm

import './cockpit-components-table.scss';

const _ = cockpit.gettext;

/* This is a wrapper around PF Table component
* See https://www.patternfly.org/components/table/
* Properties (all optional unless specified otherwise):
Expand Down Expand Up @@ -259,9 +263,13 @@ export const ListingTable = ({
<Table {...extraProps} {...tableProps}>
{showHeader && <Thead>
<Tr>
{isExpandable && <Th />}
{!onHeaderSelect && onSelect && <Th />}
{onHeaderSelect && onSelect && <Th select={{
{/* HACK - https://github.com/patternfly/patternfly/issues/6643
We should probably be using screenReaderText instead of aria-label
for the first two here, but that will change the table layout.
*/}
{isExpandable && <Th aria-label={_("Row expansion")} />}
{!onHeaderSelect && onSelect && <Th aria-label={_("Row select")} />}
{onHeaderSelect && onSelect && <Th aria-label={_("Row select")} select={{
onSelect: onHeaderSelect,
isSelected: rows.every(r => r.selected)
}} />}
Expand Down

0 comments on commit c027d89

Please sign in to comment.