diff --git a/packages/block-library/src/table/edit.js b/packages/block-library/src/table/edit.js index bce19972c215df..f733d988138ae5 100644 --- a/packages/block-library/src/table/edit.js +++ b/packages/block-library/src/table/edit.js @@ -107,8 +107,14 @@ export default class TableEdit extends Component { * @param {Array} content A RichText content value. */ onChange( content ) { + const { selectedCell } = this.state; + + if ( ! selectedCell ) { + return; + } + const { attributes, setAttributes } = this.props; - const { section, rowIndex, columnIndex } = this.state.selectedCell; + const { section, rowIndex, columnIndex } = selectedCell; setAttributes( updateCellContent( attributes, { section, @@ -124,8 +130,14 @@ export default class TableEdit extends Component { * @param {number} delta Offset for selected row index at which to insert. */ onInsertRow( delta ) { + const { selectedCell } = this.state; + + if ( ! selectedCell ) { + return; + } + const { attributes, setAttributes } = this.props; - const { section, rowIndex } = this.state.selectedCell; + const { section, rowIndex } = selectedCell; this.setState( { selectedCell: null } ); setAttributes( insertRow( attributes, { @@ -152,8 +164,14 @@ export default class TableEdit extends Component { * Deletes the currently selected row. */ onDeleteRow() { + const { selectedCell } = this.state; + + if ( ! selectedCell ) { + return; + } + const { attributes, setAttributes } = this.props; - const { section, rowIndex } = this.state.selectedCell; + const { section, rowIndex } = selectedCell; this.setState( { selectedCell: null } ); setAttributes( deleteRow( attributes, { section, rowIndex } ) ); @@ -165,8 +183,14 @@ export default class TableEdit extends Component { * @param {number} delta Offset for selected column index at which to insert. */ onInsertColumn( delta = 0 ) { + const { selectedCell } = this.state; + + if ( ! selectedCell ) { + return; + } + const { attributes, setAttributes } = this.props; - const { section, columnIndex } = this.state.selectedCell; + const { section, columnIndex } = selectedCell; this.setState( { selectedCell: null } ); setAttributes( insertColumn( attributes, { @@ -193,8 +217,14 @@ export default class TableEdit extends Component { * Deletes the currently selected column. */ onDeleteColumn() { + const { selectedCell } = this.state; + + if ( ! selectedCell ) { + return; + } + const { attributes, setAttributes } = this.props; - const { section, columnIndex } = this.state.selectedCell; + const { section, columnIndex } = selectedCell; this.setState( { selectedCell: null } ); setAttributes( deleteColumn( attributes, { section, columnIndex } ) );