Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { createContext } from '@wordpress/element';
import { withSelect } from '@wordpress/data';
import { getDefaultBlockName } from '@wordpress/blocks';

Expand All @@ -18,13 +17,6 @@ import DefaultBlockAppender from '../default-block-appender';
import ButtonBlockAppender from '../button-block-appender';
import { store as blockEditorStore } from '../../store';

// A Context to store the map of the appender map.
export const AppenderNodesContext = createContext();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is dead code.


function stopPropagation( event ) {
event.stopPropagation();
}

function BlockListAppender( {
blockClientIds,
rootClientId,
Expand Down Expand Up @@ -91,9 +83,6 @@ function BlockListAppender( {
//
// See: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
tabIndex={ -1 }
// Prevent the block from being selected when the appender is
// clicked.
onFocus={ stopPropagation }
className={ classnames( 'block-list-appender', className ) }
>
{ appender }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,7 @@ export function useFocusFirstElement( clientId ) {
const target =
( isReverse ? last : first )( textInputs ) || ref.current;

if (
// Don't focus inner block or block appenders.
! isInsideRootBlock( ref.current, target ) ||
target.closest( '.block-list-appender' )
) {
if ( ! isInsideRootBlock( ref.current, target ) ) {
ref.current.focus();
return;
}
Expand Down
13 changes: 8 additions & 5 deletions packages/block-editor/src/utils/dom.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const BLOCK_SELECTOR = '.block-editor-block-list__block';
const APPENDER_SELECTOR = '.block-list-appender';

/**
* Returns true if two elements are contained within the same block.
Expand All @@ -13,17 +14,19 @@ export function isInSameBlock( a, b ) {
}

/**
* Returns true if an element is considered part of the block and not its
* children.
* Returns true if an element is considered part of the block and not its inner
* blocks or appender.
*
* @param {Element} blockElement Block container element.
* @param {Element} element Element.
*
* @return {boolean} Whether element is in the block Element but not its
* children.
* @return {boolean} Whether an element is considered part of the block and not
* its inner blocks or appender.
*/
export function isInsideRootBlock( blockElement, element ) {
const parentBlock = element.closest( BLOCK_SELECTOR );
const parentBlock = element.closest(
[ BLOCK_SELECTOR, APPENDER_SELECTOR ].join( ',' )
);
return parentBlock === blockElement;
}

Expand Down