Skip to content

Commit

Permalink
Auto-scroll content if focused and covered by toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
joedolson committed Aug 4, 2024
1 parent 062ada2 commit 0b1a0a0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/js/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,24 @@ function eraseCookie(name) {
return false;
});

var focusable = document.querySelectorAll('input,a,select,textarea,button');
focusable.forEach((el) => {
el.addEventListener( 'focus', function() {
var bounds = el.getBoundingClientRect();
var toolbar = document.querySelector( '.a11y-toolbar' ).getBoundingClientRect();
console.log( { bounds, toolbar } );

var overlap = !(
bounds.top > toolbar.bottom ||
bounds.right < toolbar.left ||
bounds.bottom < toolbar.top ||
bounds.left > toolbar.right
);
if ( overlap ) {
var diff = bounds.bottom - toolbar.top;
window.scrollBy( 0, diff );
}
});
});

} )( jQuery );

0 comments on commit 0b1a0a0

Please sign in to comment.