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