( function( window, document ) {
  function carpentry_contractor_keepFocusInMenu() {
    document.addEventListener( 'keydown', function( e ) {
      const carpentry_contractor_nav = document.querySelector( '.sidenav' );
      if ( ! carpentry_contractor_nav || ! carpentry_contractor_nav.classList.contains( 'open' ) ) {
        return;
      }
      const elements = [...carpentry_contractor_nav.querySelectorAll( 'input, a, button' )],
        carpentry_contractor_lastEl = elements[ elements.length - 1 ],
        carpentry_contractor_firstEl = elements[0],
        carpentry_contractor_activeEl = document.activeElement,
        tabKey = e.keyCode === 9,
        shiftKey = e.shiftKey;
      if ( ! shiftKey && tabKey && carpentry_contractor_lastEl === carpentry_contractor_activeEl ) {
        e.preventDefault();
        carpentry_contractor_firstEl.focus();
      }
      if ( shiftKey && tabKey && carpentry_contractor_firstEl === carpentry_contractor_activeEl ) {
        e.preventDefault();
        carpentry_contractor_lastEl.focus();
      }
    } );
  }
  carpentry_contractor_keepFocusInMenu();
} )( window, document );