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

Table block: Fix focus loss in between row/column insertions. #23508

Merged
merged 4 commits into from
Jul 6, 2020
Merged
Changes from 1 commit
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
21 changes: 17 additions & 4 deletions packages/block-library/src/table/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,21 @@ export class TableEdit extends Component {

const { attributes, setAttributes } = this.props;
const { sectionName, rowIndex } = selectedCell;
const newRowIndex = rowIndex + delta;

this.setState( { selectedCell: null } );
setAttributes(
insertRow( attributes, {
sectionName,
rowIndex: rowIndex + delta,
rowIndex: newRowIndex,
} )
);
// this just allows to be able to add more rows, by enabling the corresponding
// buttons. It needs to be revised when programmatically focus to RichText is handled
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
this.createOnFocus( {
sectionName,
rowIndex: newRowIndex,
columnIndex: 0,
} );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By definition, createOnFocus just returns a new function but doesn't do anything with it. So I'm fairly sure that nothing is happening here. :)

Copy link
Contributor Author

@ntsekouras ntsekouras Jul 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Miguel. I saw the code now and couldn't understand why I left it that way... Maybe when I was trying to find how to focus on RichText..?

I changed it to just change the selected cell in state.

}

/**
Expand Down Expand Up @@ -346,13 +353,19 @@ export class TableEdit extends Component {

const { attributes, setAttributes } = this.props;
const { columnIndex } = selectedCell;
const newColumnIndex = columnIndex + delta;

this.setState( { selectedCell: null } );
setAttributes(
insertColumn( attributes, {
columnIndex: columnIndex + delta,
columnIndex: newColumnIndex,
} )
);
// this just allows to be able to add more rows, by enabling the corresponding
// buttons. It needs to be revised when programmatically focus to RichText is handled
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
this.createOnFocus( {
rowIndex: 0,
columnIndex: newColumnIndex,
} );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same observation as for rows.

}

/**
Expand Down