-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Safari: prevent focus capturing caused by flex display
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
packages/rich-text/src/component/event-listeners/prevent-focus-capture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
}; | ||
}; |