Skip to content

Commit

Permalink
Use getBlockSelectionStart which also allows to simplify.
Browse files Browse the repository at this point in the history
  • Loading branch information
afercia committed Apr 4, 2018
1 parent c31ba95 commit eb20646
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions editor/components/skip-to-selected-block/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@ import { __ } from '@wordpress/i18n';
import './style.scss';
import { getBlockFocusableWrapper } from '../../utils/dom';

const SkipToSelectedBlock = ( { selectedBlock } ) => {
if ( ! selectedBlock ) {
return null;
}

const { uid } = selectedBlock;

const SkipToSelectedBlock = ( { selectedBlockUID } ) => {
const onClick = () => {
const selectedBlockElement = getBlockFocusableWrapper( uid );
const selectedBlockElement = getBlockFocusableWrapper( selectedBlockUID );
selectedBlockElement.focus();
};

return (
selectedBlock && uid &&
selectedBlockUID &&
<button type="button" className="button editor-skip-to-selected-block" onClick={ onClick }>
{ __( 'Skip to the selected block' ) }
</button>
Expand All @@ -32,6 +26,6 @@ const SkipToSelectedBlock = ( { selectedBlock } ) => {

export default withSelect( ( select ) => {
return {
selectedBlock: select( 'core/editor' ).getSelectedBlock(),
selectedBlockUID: select( 'core/editor' ).getBlockSelectionStart(),
};
} )( SkipToSelectedBlock );

0 comments on commit eb20646

Please sign in to comment.