Skip to content

Commit

Permalink
ff compat
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Nov 28, 2024
1 parent 814bcf3 commit 63753cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { useIntersectionObserver } from './use-intersection-observer';
import { useScrollIntoView } from './use-scroll-into-view';
import { useFlashEditableBlocks } from '../../use-flash-editable-blocks';
import { canBindBlock } from '../../../hooks/use-bindings-attributes';
import { useFirefoxDraggableCompatibility } from './use-firefox-draggable-compatibility';

/**
* This hook is used to lightly mark an element as a block element. The element
Expand Down Expand Up @@ -106,6 +107,7 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
// translators: %s: Type of block (i.e. Text, Image etc)
const blockLabel = sprintf( __( 'Block: %s' ), blockTitle );
const htmlSuffix = mode === 'html' && ! __unstableIsHtml ? '-visual' : '';
const ffDragRef = useFirefoxDraggableCompatibility();
const mergedRefs = useMergeRefs( [
props.ref,
useFocusFirstElement( { clientId, initialPosition } ),
Expand All @@ -121,6 +123,7 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {
isEnabled: isSectionBlock,
} ),
useScrollIntoView( { isSelected } ),
canMove ? ffDragRef : undefined,
] );

const blockEditContext = useBlockEditContext();
Expand Down Expand Up @@ -153,7 +156,7 @@ export function useBlockProps( props = {}, { __unstableIsHtml } = {} ) {

return {
tabIndex: blockEditingMode === 'disabled' ? -1 : 0,
draggable: ! hasChildSelected && canMove ? true : undefined,
draggable: canMove ? true : undefined,
...wrapperProps,
...props,
ref: mergedRefs,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* WordPress dependencies
*/
import { useRefEffect } from '@wordpress/compose';

export function useFirefoxDraggableCompatibility() {
return useRefEffect( ( node ) => {
function onDown( event ) {
if ( event.target.isContentEditable ) {
node.draggable = false;
} else {
node.draggable = true;
}
}
const { ownerDocument } = node;
ownerDocument.addEventListener( 'pointerdown', onDown );
return () => {
ownerDocument.removeEventListener( 'pointerdown', onDown );
};
}, [] );
}

0 comments on commit 63753cf

Please sign in to comment.