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