Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aria selected and row attributes #491

Merged
merged 6 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/FixedDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,12 @@ class FixedDataTable extends React.Component {
footerHeight: PropTypes.number,
groupHeaderHeight: PropTypes.number,
headerHeight: PropTypes.number,
})
}),

/**
* Callback that returns an object of html attributes to add to the grid element
*/
gridAttributesGetter: PropTypes.func,
}

static defaultProps = /*object*/ {
Expand Down Expand Up @@ -660,6 +665,7 @@ class FixedDataTable extends React.Component {
elementHeights,
isColumnReordering,
isColumnResizing,
gridAttributesGetter,
maxScrollX,
maxScrollY,
onColumnReorderEndCallback,
Expand All @@ -676,6 +682,7 @@ class FixedDataTable extends React.Component {
const { cellGroupWrapperHeight, footerHeight, groupHeaderHeight, headerHeight } = elementHeights;
const { scrollEnabledX, scrollEnabledY } = scrollbarsVisible(this.props);
const onColumnReorder = onColumnReorderEndCallback ? this._onColumnReorder : null;
const attributes = gridAttributesGetter && gridAttributesGetter();

let groupHeader;
if (groupHeaderHeight > 0) {
Expand Down Expand Up @@ -849,6 +856,7 @@ class FixedDataTable extends React.Component {
)}
role="grid"
aria-rowcount={ariaRowCount}
{...attributes}
tabIndex={tabIndex}
onKeyDown={this._onKeyDown}
onTouchStart={touchScrollEnabled ? this._touchHandler.onTouchStart : null}
Expand Down
2 changes: 2 additions & 0 deletions src/FixedDataTableBufferedRows.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class FixedDataTableBufferedRows extends React.Component {
rowOffsets: PropTypes.object.isRequired,
rowKeyGetter: PropTypes.func,
rowSettings: PropTypes.shape({
rowAttributesGetter: PropTypes.func,
rowHeightGetter: PropTypes.func,
rowsCount: PropTypes.number.isRequired,
subRowHeightGetter: PropTypes.func,
Expand Down Expand Up @@ -126,6 +127,7 @@ class FixedDataTableBufferedRows extends React.Component {
rowProps.subRowHeight = this.props.rowSettings.subRowHeightGetter(rowIndex);
rowProps.offsetTop = Math.round(baseOffsetTop + props.rowOffsets[rowIndex]);
rowProps.key = props.rowKeyGetter ? props.rowKeyGetter(rowIndex) : key;
rowProps.attributes = props.rowSettings.rowAttributesGetter && props.rowSettings.rowAttributesGetter(rowIndex);

const hasBottomBorder = (rowIndex === props.rowSettings.rowsCount - 1) && props.showLastRowBorder;
rowProps.className = joinClasses(
Expand Down
6 changes: 6 additions & 0 deletions src/FixedDataTableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ class FixedDataTableRowImpl extends React.Component {
* The value of the aria-rowindex attribute.
*/
ariaRowIndex: PropTypes.number,

/**
* DOM attributes to be applied to the row.
*/
attributes: PropTypes.object,
};

render() /*object*/ {
Expand Down Expand Up @@ -281,6 +286,7 @@ class FixedDataTableRowImpl extends React.Component {
className={joinClasses(className, this.props.className)}
role={'row'}
aria-rowindex={this.props.ariaRowIndex}
{...this.props.attributes}
onClick={this.props.onClick ? this._onClick : null}
onContextMenu={this.props.onContextMenu ? this._onContextMenu : null}
onDoubleClick={this.props.onDoubleClick ? this._onDoubleClick : null}
Expand Down
2 changes: 2 additions & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function getInitialState() {
},
rowSettings: {
bufferRowCount: undefined,
rowAttributesGetter: undefined,
rowHeight: 0,
rowHeightGetter: () => 0,
rowsCount: 0,
Expand Down Expand Up @@ -248,6 +249,7 @@ function setStateFromProps(state, props) {
props.rowHeightGetter || (() => rowHeight);
newState.rowSettings.subRowHeightGetter =
props.subRowHeightGetter || (() => subRowHeight || 0);
newState.rowSettings.rowAttributesGetter = props.rowAttributesGetter;

newState.scrollFlags = Object.assign({}, newState.scrollFlags,
pick(props, ['overflowX', 'overflowY', 'showScrollbarX', 'showScrollbarY']));
Expand Down