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
6 changes: 6 additions & 0 deletions packages/block-editor/src/components/block-list/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ function BlockListBlockProvider( props ) {
isSelectionEnabled,
getTemplateLock,
isSectionBlock: _isSectionBlock,
getParentSectionBlock,
getBlockWithoutAttributes,
getBlockAttributes,
canRemoveBlock,
Expand Down Expand Up @@ -674,6 +675,9 @@ function BlockListBlockProvider( props ) {
isSelectionEnabled: isSelectionEnabled(),
isLocked: !! getTemplateLock( rootClientId ),
isSectionBlock: _isSectionBlock( clientId ),
isWithinSectionBlock:
_isSectionBlock( clientId ) ||
!! getParentSectionBlock( clientId ),
canRemove,
canMove,
isSelected: _isSelected,
Expand Down Expand Up @@ -756,6 +760,7 @@ function BlockListBlockProvider( props ) {
isDragging,
hasChildSelected,
isSectionBlock,
isWithinSectionBlock,
isEditingDisabled,
hasEditableOutline,
className,
Expand Down Expand Up @@ -802,6 +807,7 @@ function BlockListBlockProvider( props ) {
isDragging,
hasChildSelected,
isSectionBlock,
isWithinSectionBlock,
isEditingDisabled,
hasEditableOutline,
isEditingContentOnlySection,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
isEditingContentOnlySection,
defaultClassName,
isSectionBlock,
isWithinSectionBlock,
canMove,
isBlockHidden,
} = useContext( PrivateBlockContext );
Expand All @@ -108,13 +109,14 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
const blockLabel = sprintf( __( 'Block: %s' ), blockTitle );
const htmlSuffix = mode === 'html' && ! __unstableIsHtml ? '-visual' : '';
const ffDragRef = useFirefoxDraggableCompatibility();
const isHoverEnabled = ! isWithinSectionBlock;
const mergedRefs = useMergeRefs( [
props.ref,
useFocusFirstElement( { clientId, initialPosition } ),
useBlockRefProvider( clientId ),
useFocusHandler( clientId ),
useEventHandlers( { clientId, isSelected } ),
useIsHovered(),
useIsHovered( { isEnabled: isHoverEnabled } ),
useIntersectionObserver(),
useMovingAnimation( { triggerAnimationOnChange: index, clientId } ),
useDisabled( { isDisabled: ! hasOverlay } ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,33 @@ function listener( event ) {
);
}

/*
/**
* Adds `is-hovered` class when the block is hovered and in navigation or
* outline mode.
*
* @param {Object} options Options object.
* @param {boolean} [options.isEnabled=true] Whether to enable hover detection.
*
* @return {Function} Ref callback.
*/
export function useIsHovered() {
return useRefEffect( ( node ) => {
node.addEventListener( 'mouseout', listener );
node.addEventListener( 'mouseover', listener );
export function useIsHovered( { isEnabled = true } = {} ) {
return useRefEffect(
( node ) => {
if ( ! isEnabled ) {
return;
}

node.addEventListener( 'mouseout', listener );
node.addEventListener( 'mouseover', listener );

return () => {
node.removeEventListener( 'mouseout', listener );
node.removeEventListener( 'mouseover', listener );
return () => {
node.removeEventListener( 'mouseout', listener );
node.removeEventListener( 'mouseover', listener );

// Remove class in case it lingers.
node.classList.remove( 'is-hovered' );
};
}, [] );
// Remove class in case it lingers.
node.classList.remove( 'is-hovered' );
};
},
[ isEnabled ]
);
}
Loading