Skip to content

Commit f7471f8

Browse files
authored
DataTable: Add "SR only" text for sortable columns (#6109)
1 parent 694dd95 commit f7471f8

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

.changeset/dry-breads-attack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': patch
3+
---
4+
5+
DataTable: Add visually hidden text to sortable DataTable column buttons

packages/react/src/DataTable/Table.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,17 @@ function TableSortHeader({align, children, direction, onToggleSort, ...rest}: Ta
150150
>
151151
{children}
152152
{direction === SortDirection.NONE || direction === SortDirection.ASC ? (
153-
<SortAscIcon
154-
className={clsx(
155-
'TableSortIcon',
156-
'TableSortIcon--ascending',
157-
classes.TableSortIcon,
158-
classes['TableSortIcon--ascending'],
159-
)}
160-
/>
153+
<>
154+
<SortAscIcon
155+
className={clsx(
156+
'TableSortIcon',
157+
'TableSortIcon--ascending',
158+
classes.TableSortIcon,
159+
classes['TableSortIcon--ascending'],
160+
)}
161+
/>
162+
{direction === SortDirection.NONE ? <VisuallyHidden>sort ascending</VisuallyHidden> : null}
163+
</>
161164
) : null}
162165
{direction === SortDirection.DESC ? (
163166
<SortDescIcon

packages/react/src/DataTable/__tests__/DataTable.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ describe('DataTable', () => {
826826

827827
// When interacting with Column B, sort order should reset to ASC
828828
await user.click(screen.getByText('Column B'))
829-
expect(getSortHeader('Column A')).not.toHaveAttribute('aria-sort')
829+
expect(getSortHeader('Column A sort ascending')).not.toHaveAttribute('aria-sort')
830830
expect(getSortHeader('Column B')).toHaveAttribute('aria-sort', 'ascending')
831831
expect(getRowOrder()).toEqual([
832832
[3, 1],

0 commit comments

Comments
 (0)