Skip to content

Commit

Permalink
fix(TableHeaderCell): should render aria-sort="none" if not sorted (#…
Browse files Browse the repository at this point in the history
…25921)

* fix(TableHeaderCell): should render `aria-sort="none"` if not sorted

Does not render `aria-sort` if not sorted

renders `aria-sort="none"` if not sorted

* changefile

* only apply aria-sort if sortable
  • Loading branch information
ling1726 authored Dec 7, 2022
1 parent b0aab3b commit ac32a5c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "fix(TableHeaderCell): should render `aria-sort=\"none\"` if not sorted",
"packageName": "@fluentui/react-table",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('TableHeaderCell', () => {
},
);

it('should not render aria-sort when column is not sorted', () => {
it('should render aria-sort "none" when column is not sorted', () => {
const { getByRole } = render(
<TableContextProvider
value={{
Expand All @@ -106,6 +106,21 @@ describe('TableHeaderCell', () => {
<TableHeaderCell>Cell</TableHeaderCell>
</TableContextProvider>,
);
expect(getByRole('columnheader').getAttribute('aria-sort')).toEqual('none');
});

it('should not render aria-sort table is not sortable', () => {
const { getByRole } = render(
<TableContextProvider
value={{
...tableContextDefaultValue,
noNativeElements: true,
sortable: false,
}}
>
<TableHeaderCell>Cell</TableHeaderCell>
</TableContextProvider>,
);
expect(getByRole('columnheader').hasAttribute('aria-sort')).toBe(false);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useTableHeaderCell_unstable = (
root: getNativeElementProps(rootComponent, {
ref,
role: rootComponent === 'div' ? 'columnheader' : undefined,
'aria-sort': props.sortDirection,
'aria-sort': sortable ? props.sortDirection ?? 'none' : undefined,
...props,
}),
sortIcon: resolveShorthand(props.sortIcon, {
Expand Down

0 comments on commit ac32a5c

Please sign in to comment.