Skip to content

Commit

Permalink
Safari: prevent focus capturing caused by flex display
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Nov 11, 2024
1 parent de52623 commit 4af6150
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/rich-text/src/component/event-listeners/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import formatBoundaries from './format-boundaries';
import deleteHandler from './delete';
import inputAndSelection from './input-and-selection';
import selectionChangeCompat from './selection-change-compat';
import preventFocusCapture from './prevent-focus-capture';

const allEventListeners = [
copyHandler,
Expand All @@ -21,6 +22,7 @@ const allEventListeners = [
deleteHandler,
inputAndSelection,
selectionChangeCompat,
preventFocusCapture,
];

export function useEventListeners( props ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export default () => ( element ) => {
const { ownerDocument } = element;
const { defaultView } = ownerDocument;

let value = null;

function onPointerDown( event ) {
// Abort if the event is default prevented, we will not get a pointer up event.
if ( event.defaultPrevented ) {
return;
}
if ( event.target === element ) {
return;
}
if ( ! event.target.contains( element ) ) {
return;
}
value = element.getAttribute( 'contenteditable' );
element.setAttribute( 'contenteditable', 'false' );
}

function onPointerUp() {
if ( value !== null ) {
element.setAttribute( 'contenteditable', value );
value = null;
}
}

defaultView.addEventListener( 'pointerdown', onPointerDown );
defaultView.addEventListener( 'pointerup', onPointerUp );
return () => {
defaultView.removeEventListener( 'pointerdown', onPointerDown );
defaultView.removeEventListener( 'pointerup', onPointerUp );
};
};

0 comments on commit 4af6150

Please sign in to comment.