Skip to content

Commit

Permalink
Scroll focused element into view (#19014)
Browse files Browse the repository at this point in the history
  • Loading branch information
frontdevde authored Dec 9, 2019
1 parent 992a9d4 commit 86b1f6e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/edit-post/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,14 @@ export function initializeEditor( id, postType, postId, settings, initialEdits )
const isIphone = window.navigator.userAgent.indexOf( 'iPhone' ) !== -1;
if ( isIphone ) {
window.addEventListener( 'scroll', function( event ) {
const editorScrollContainer = document.getElementsByClassName( 'edit-post-editor-regions__body' )[ 0 ];
if ( event.target === document ) {
// Scroll element into view by scrolling the editor container by the same amount
// that Mobile Safari tried to scroll the html element upwards.
if ( window.scrollY > 100 ) {
editorScrollContainer.scrollTop = editorScrollContainer.scrollTop + window.scrollY;
}
//Undo unwanted scroll on html element
window.scrollTo( 0, 0 );
}
} );
Expand Down

0 comments on commit 86b1f6e

Please sign in to comment.