Skip to content

Commit

Permalink
Enable add row/column buttons after having added one (#23508)
Browse files Browse the repository at this point in the history
* Enable add row/column buttons after having added one.

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.

* set selected cell in state

* Change comment description

Co-authored-by: Miguel Fonseca <[email protected]>

* Change comment description

Co-authored-by: Miguel Fonseca <[email protected]>

Co-authored-by: Miguel Fonseca <[email protected]>
  • Loading branch information
2 people authored and youknowriad committed Jul 13, 2020
1 parent 73b6762 commit 3c93dec
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 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,23 @@ 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,
} )
);
// Select the first cell of the new row
this.setState( {
selectedCell: {
sectionName,
rowIndex: newRowIndex,
columnIndex: 0,
type: 'cell',
},
} );
}

/**
Expand Down Expand Up @@ -346,13 +355,21 @@ 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,
} )
);
// Select the first cell of the new column
this.setState( {
selectedCell: {
rowIndex: 0,
columnIndex: newColumnIndex,
type: 'cell',
},
} );
}

/**
Expand Down

0 comments on commit 3c93dec

Please sign in to comment.