Skip to content

Commit 28d0092

Browse files
committed
move aria-sort
1 parent c060c7c commit 28d0092

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

packages/gamut/src/DataList/Controls/SortControl.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,6 @@ export const SortControl: React.FC<SortControlProps> = ({
6262
return (
6363
<SortAnchor
6464
aria-label={`sort by ${columnKey}`}
65-
aria-sort={
66-
direction === 'none'
67-
? 'none'
68-
: direction === 'asc'
69-
? 'ascending'
70-
: 'descending'
71-
}
7265
display="inline-flex"
7366
variant="interface"
7467
onClick={() =>

packages/gamut/src/DataList/Tables/Rows/TableHeaderRow.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
SortControl,
1111
} from '../../Controls';
1212
import { useControlContext } from '../../hooks/useListControls';
13+
import { useListState } from '../../hooks/useListState';
1314
import { ColumnConfig, Query } from '../../types';
1415
import { StyledHeaderRow } from './elements';
1516

@@ -35,6 +36,7 @@ export const TableHeaderRow: HeaderComponent = ({
3536
useControlContext();
3637
const { variant, listType } = useListContext();
3738
const dataTablePadding = listType === 'table' && variant === 'table';
39+
const headerRowDirections = useListState().query?.sort;
3840

3941
return (
4042
<StyledHeaderRow
@@ -60,11 +62,19 @@ export const TableHeaderRow: HeaderComponent = ({
6062
const rowProperty = key as string;
6163
const renderKey = prefixId(`header-col-${rowProperty}`);
6264
const columnText = String(header || key);
65+
const sortDirection = headerRowDirections?.[rowProperty] ?? 'none';
6366

6467
return (
6568
<ListCol
6669
key={renderKey}
6770
{...colProps}
71+
aria-sort={
72+
!sortable || sortDirection === 'none'
73+
? 'none'
74+
: sortDirection === 'asc'
75+
? 'ascending'
76+
: 'descending'
77+
}
6878
columnHeader
6979
dataTablePadding={dataTablePadding}
7080
>

packages/gamut/src/List/ListCol.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,40 @@ export interface ListColProps
88
extends PublicListProps<ComponentProps<typeof ColEl>> {}
99

1010
export const ListCol = forwardRef<HTMLDivElement, ListColProps>(
11-
({ type, ...rest }, ref) => {
11+
({ type, columnHeader, 'aria-sort': ariaSort, ...rest }, ref) => {
1212
const { listType, scrollable, ...activeVariants } = useListContext();
1313
const isOl = listType === 'ol';
1414
const isTable = listType === 'table';
1515
const isHeader = type === 'header';
1616
const sticky = isHeader && scrollable;
1717
const isOrderedHeader = isOl && isHeader;
18+
1819
const colEl =
19-
isTable && !sticky && isHeader ? 'th' : !isTable || sticky ? 'div' : 'td';
20+
isTable && !sticky && (isHeader || columnHeader)
21+
? 'th'
22+
: !isTable || sticky
23+
? 'div'
24+
: 'td';
2025

2126
const col = (
2227
<ColEl
2328
{...activeVariants}
2429
{...rest}
30+
aria-sort={!sticky && ariaSort ? ariaSort : undefined}
2531
as={colEl}
32+
columnHeader={columnHeader}
2633
delimiter={sticky && activeVariants.variant === 'table'}
2734
lastChildPadding={!(type === 'expandControl')}
2835
ref={ref}
2936
sticky={sticky}
3037
type={isOrderedHeader ? 'orderedHeader' : type}
3138
/>
3239
);
40+
3341
if (sticky) {
3442
return (
3543
<StickyHeaderColWrapper
44+
aria-sort={ariaSort}
3645
as={isTable ? 'th' : 'div'}
3746
data-testid="header-container"
3847
>

packages/styleguide/src/lib/Organisms/Lists & Tables/DataTable/DataTable.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ The example below demonstrates the difference between default container query be
184184

185185
## Playground
186186

187-
If you are using a story named 'Default', you can forgo the `of` prop.
188-
189187
<Canvas sourceState="shown" of={DataTableStories.Default} />
190188

191189
<Controls />

0 commit comments

Comments
 (0)