Skip to content

Commit

Permalink
Select the first cell of the table block when initialised (#1755)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiny-james authored and nylen committed Jul 6, 2017
1 parent 3037de6 commit 313e6c3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion blocks/library/table/table-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,25 @@ const TABLE_CONTROLS = [
export default class TableBlock extends wp.element.Component {
constructor() {
super();
this.handleSetup = this.handleSetup.bind( this );
this.state = {
editor: null,
};
}

handleSetup( editor ) {
// select the end of the first table cell
editor.on( 'init', () => {
const cell = editor.getBody().querySelector( 'td,th' );
if ( cell ) {
cell.focus();
editor.selection.select( cell, true );
editor.selection.collapse( false );
}
} );
this.setState( { editor } );
}

render() {
const { content, focus, onFocus, onChange, className } = this.props;

Expand All @@ -63,7 +77,7 @@ export default class TableBlock extends wp.element.Component {
...settings,
plugins: ( settings.plugins || [] ).concat( 'table' ),
} ) }
onSetup={ ( editor ) => this.setState( { editor } ) }
onSetup={ this.handleSetup }
onChange={ onChange }
value={ content }
focus={ focus }
Expand Down

0 comments on commit 313e6c3

Please sign in to comment.