Skip to content

Commit

Permalink
chore: includes label for select all checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
cafrias authored and aferro-wwnorton committed Apr 9, 2024
1 parent 274dab7 commit ede3d4e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
7 changes: 2 additions & 5 deletions packages/react/src/components/Table/TableHeadCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const TableHeadCell: React.FC<TableHeadCellProps> = ({
className: tableHeadCellClassName = 'nds-table__head-cell',
sortType,
children,
'aria-label': ariaLabel,
onSort,
}) => {
const tableHeadCellClass = className(tableHeadCellClassName, {
Expand All @@ -15,11 +16,7 @@ export const TableHeadCell: React.FC<TableHeadCellProps> = ({
});

return (
<th
className={tableHeadCellClass}
aria-sort={sortType}
onClick={onSort}
>
<th className={tableHeadCellClass} aria-sort={sortType} onClick={onSort} aria-label={ariaLabel}>
{children}
</th>
);
Expand Down
23 changes: 17 additions & 6 deletions packages/react/src/components/Table/TableHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,32 @@ import { Checkbox } from '../Checkbox';
import { useId } from '../../utilities';
import { TableRow } from './TableRow';

export const TableHeader: React.FC<TableHeaderProps> = ({ children, className = 'nds-table__header' }) => {
const SELECT_ALL_HEADER_LABEL = 'Select All';

export const TableHeader: React.FC<TableHeaderProps> = ({
children,
className = 'nds-table__header',
}) => {
const { selectable, onSelect, onSelectedAll, isSelectedAll } = useTableState();
const uniqueId = useId();

return (
<thead className={className}>
<TableRow isHeader>
{ selectable && onSelect ? (
<TableHeadCell>
<Checkbox id={uniqueId} checked={isSelectedAll} onChange={onSelectedAll} />
{selectable && onSelect ? (
<TableHeadCell aria-label={SELECT_ALL_HEADER_LABEL}>
<Checkbox
id={uniqueId}
checked={isSelectedAll}
labelClass="nds-sr-only"
onChange={onSelectedAll}
>
{SELECT_ALL_HEADER_LABEL}
</Checkbox>
</TableHeadCell>
) : null }
) : null}
{children}
</TableRow>

</thead>
);
};
1 change: 1 addition & 0 deletions packages/react/src/components/Table/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface TableHeadCellProps {
className?: string;
sortType?: 'none' | 'ascending' | 'descending' | 'other' | undefined;
onSort?: VoidFunction;
'aria-label'?: string;
}

export interface TableHeaderProps {
Expand Down

0 comments on commit ede3d4e

Please sign in to comment.