Skip to content

Commit

Permalink
fixed #2575 - Add selectionAutoFocus property to DataTable
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Jan 14, 2022
1 parent f757201 commit bf3f625
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions components/lib/datatable/BodyRow.js
Expand Up @@ -127,6 +127,10 @@ export class BodyRow extends Component {
}

onClick(event) {
const row = event.currentTarget;
const tabbableEl = DomHandler.findSingle(row.parentElement, 'tr[tabIndex="0"]');
tabbableEl && this.changeTabIndex(tabbableEl, row);

this.props.onRowClick({ originalEvent: event, data: this.props.rowData, index: this.props.index });
}

Expand Down
6 changes: 4 additions & 2 deletions components/lib/datatable/DataTable.js
Expand Up @@ -53,6 +53,7 @@ export class DataTable extends Component {
metaKeySelection: true,
selectOnEdit: true,
selectionPageOnly: false,
selectionAutoFocus: true,
showSelectAll: true,
selectAll: false,
onSelectAllChange: null,
Expand Down Expand Up @@ -180,6 +181,7 @@ export class DataTable extends Component {
metaKeySelection: PropTypes.bool,
selectOnEdit: PropTypes.bool,
selectionPageOnly: PropTypes.bool,
selectionAutoFocus: PropTypes.bool,
showSelectAll: PropTypes.bool,
selectAll: PropTypes.bool,
onSelectAllChange: PropTypes.func,
Expand Down Expand Up @@ -1638,7 +1640,7 @@ export class DataTable extends Component {
rowGroupHeaderTemplate={this.props.rowGroupHeaderTemplate} rowExpansionTemplate={this.props.rowExpansionTemplate} rowGroupFooterTemplate={this.props.rowGroupFooterTemplate}
onRowEditChange={this.props.onRowEditChange} compareSelectionBy={this.props.compareSelectionBy} selectOnEdit={this.props.selectOnEdit}
onRowEditInit={this.props.onRowEditInit} rowEditValidator={this.props.rowEditValidator} onRowEditSave={this.props.onRowEditSave} onRowEditComplete={this.props.onRowEditComplete} onRowEditCancel={this.props.onRowEditCancel}
cellClassName={this.props.cellClassName} responsiveLayout={this.props.responsiveLayout}
cellClassName={this.props.cellClassName} responsiveLayout={this.props.responsiveLayout} selectionAutoFocus={this.props.selectionAutoFocus}
showSelectionElement={this.props.showSelectionElement} showRowReorderElement={this.props.showRowReorderElement}
expandedRowIcon={this.props.expandedRowIcon} collapsedRowIcon={this.props.collapsedRowIcon} rowClassName={this.props.rowClassName}
isVirtualScrollerDisabled={true} />
Expand All @@ -1658,7 +1660,7 @@ export class DataTable extends Component {
rowGroupHeaderTemplate={this.props.rowGroupHeaderTemplate} rowExpansionTemplate={this.props.rowExpansionTemplate} rowGroupFooterTemplate={this.props.rowGroupFooterTemplate}
onRowEditChange={this.props.onRowEditChange} compareSelectionBy={this.props.compareSelectionBy} selectOnEdit={this.props.selectOnEdit}
onRowEditInit={this.props.onRowEditInit} rowEditValidator={this.props.rowEditValidator} onRowEditSave={this.props.onRowEditSave} onRowEditComplete={this.props.onRowEditComplete} onRowEditCancel={this.props.onRowEditCancel}
cellClassName={this.props.cellClassName} responsiveLayout={this.props.responsiveLayout}
cellClassName={this.props.cellClassName} responsiveLayout={this.props.responsiveLayout} selectionAutoFocus={this.props.selectionAutoFocus}
showSelectionElement={this.props.showSelectionElement} showRowReorderElement={this.props.showRowReorderElement}
expandedRowIcon={this.props.expandedRowIcon} collapsedRowIcon={this.props.collapsedRowIcon} rowClassName={this.props.rowClassName}
virtualScrollerContentRef={contentRef} virtualScrollerOptions={options} isVirtualScrollerDisabled={isVirtualScrollerDisabled} />
Expand Down
2 changes: 1 addition & 1 deletion components/lib/datatable/TableBody.js
Expand Up @@ -441,7 +441,7 @@ export class TableBody extends Component {
focusOnElement(event, isFocused) {
const target = event.currentTarget;

if (!this.allowCellSelection()) {
if (!this.allowCellSelection() && this.props.selectionAutoFocus) {
if (this.isCheckboxSelectionModeInColumn()) {
const checkbox = DomHandler.findSingle(target, 'td.p-selection-column .p-checkbox-box');
checkbox && checkbox.focus();
Expand Down

0 comments on commit bf3f625

Please sign in to comment.