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