Skip to content

Commit 1c31744

Browse files
committed
feat(tableheadcell): add 'sort' prop and corresponding aria label
1 parent 2662c95 commit 1c31744

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/components/TableHeadCell/TableHeadCell.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,18 @@ user-select: none;
5555
`;
5656

5757
const TableHeadCell = React.forwardRef(function TableHeadCell(props, ref) {
58-
const { disabled, children, onClick, ...otherProps } = props;
59-
58+
const { disabled, children, onClick, sort, ...otherProps } = props;
59+
let sortDirection = null;
60+
if (sort) {
61+
sortDirection = sort === 'asc' ? 'ascending' : 'descending';
62+
}
6063
return (
6164
<StyledHeadCell
6265
ref={ref}
6366
isDisabled={disabled}
6467
aria-disabled={disabled}
6568
onClick={disabled ? undefined : onClick}
69+
aria-sort={sortDirection}
6670
{...otherProps}
6771
>
6872
<div>{children}</div>
@@ -75,14 +79,16 @@ TableHeadCell.defaultProps = {
7579
disabled: false,
7680
onClick: null,
7781
// onTouchStart below to enable :active style on iOS
78-
onTouchStart: noOp
82+
onTouchStart: noOp,
83+
sort: null
7984
};
8085

8186
TableHeadCell.propTypes = {
8287
children: propTypes.node,
8388
disabled: propTypes.bool,
8489
onClick: propTypes.func,
85-
onTouchStart: propTypes.func
90+
onTouchStart: propTypes.func,
91+
sort: propTypes.oneOf(['asc', 'desc', null])
8692
};
8793

8894
export default TableHeadCell;

0 commit comments

Comments
 (0)