Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
#2436 re-focus on table cell if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
siemiatj committed Nov 27, 2019
1 parent ee78d08 commit 60b4a55
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/components/table/TableItem.js
Expand Up @@ -42,7 +42,8 @@ class TableItem extends PureComponent {
}

componentDidUpdate(prevProps) {
const { multilineText } = this.state;
const { multilineText, activeCell } = this.state;
const { focusOnFieldName, isSelected } = this.props;

if (multilineText && this.props.isSelected !== prevProps.isSelected) {
this.handleCellExtend();
Expand All @@ -53,6 +54,12 @@ class TableItem extends PureComponent {
editedCells: {},
});
}

if (focusOnFieldName && isSelected && this.autofocusCell && !activeCell) {
// eslint-disable-next-line react/no-find-dom-node
ReactDOM.findDOMNode(this.autofocusCell).focus();
this.focusCell();
}
}

componentDidMount() {
Expand Down Expand Up @@ -118,7 +125,12 @@ class TableItem extends PureComponent {
}
};

handleEditProperty = (e, property, callback, item) => {
handleEditProperty = (e, property, focus, item) => {
this.focusCell();
this.editProperty(e, property, focus, item, select);
};

focusCell = () => {
const { activeCell } = this.state;
const elem = document.activeElement;

Expand All @@ -127,8 +139,6 @@ class TableItem extends PureComponent {
activeCell: elem,
});
}

this.editProperty(e, property, callback, item);
};

prepareWidgetData = item => {
Expand All @@ -138,7 +148,7 @@ class TableItem extends PureComponent {
return widgetData;
};

editProperty = (e, property, callback, item) => {
editProperty = (e, property, focus, item) => {
if (item ? !item.readonly : true) {
if (this.state.edited === property) e.stopPropagation();

Expand All @@ -147,7 +157,7 @@ class TableItem extends PureComponent {
edited: property,
},
() => {
if (callback) {
if (focus) {
const elem = document.activeElement.getElementsByClassName(
'js-input-field'
)[0];
Expand Down Expand Up @@ -610,6 +620,7 @@ TableItem.propTypes = {
lastChild: PropTypes.string,
includedDocuments: PropTypes.string,
contextType: PropTypes.string,
focusOnFieldName: PropTypes.string,
};

export default connect(
Expand Down

0 comments on commit 60b4a55

Please sign in to comment.