Skip to content

Commit

Permalink
feat(tableheadcell): add 'sort' prop and corresponding aria label
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbien committed Apr 4, 2020
1 parent 2662c95 commit 1c31744
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/components/TableHeadCell/TableHeadCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,18 @@ user-select: none;
`;

const TableHeadCell = React.forwardRef(function TableHeadCell(props, ref) {
const { disabled, children, onClick, ...otherProps } = props;

const { disabled, children, onClick, sort, ...otherProps } = props;
let sortDirection = null;
if (sort) {
sortDirection = sort === 'asc' ? 'ascending' : 'descending';
}
return (
<StyledHeadCell
ref={ref}
isDisabled={disabled}
aria-disabled={disabled}
onClick={disabled ? undefined : onClick}
aria-sort={sortDirection}
{...otherProps}
>
<div>{children}</div>
Expand All @@ -75,14 +79,16 @@ TableHeadCell.defaultProps = {
disabled: false,
onClick: null,
// onTouchStart below to enable :active style on iOS
onTouchStart: noOp
onTouchStart: noOp,
sort: null
};

TableHeadCell.propTypes = {
children: propTypes.node,
disabled: propTypes.bool,
onClick: propTypes.func,
onTouchStart: propTypes.func
onTouchStart: propTypes.func,
sort: propTypes.oneOf(['asc', 'desc', null])
};

export default TableHeadCell;

0 comments on commit 1c31744

Please sign in to comment.