function trapFocus() {
	  var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
	  var toggle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

	  if (!is$1.element(element)) {
	    return;
	  }

	  var focusable = getElements.call(this, 'button:not(:disabled), input:not(:disabled), [tabindex]');
	  var first = focusable[0];
	  var last = focusable[focusable.length - 1];

	  var trap = function trap(event) {
	    // Bail if not tab key or not fullscreen
	    if (event.key !== 'Tab' || event.keyCode !== 9) {
	      return;
	    } // Get the current focused element


	    var focused = document.activeElement;

	    if (focused === last && !event.shiftKey) {
	      // Move focus to first element that can be tabbed if Shift isn't used
	      first.focus();
	      event.preventDefault();
	    } else if (focused === first && event.shiftKey) {
	      // Move focus to last element that can be tabbed if Shift is used
	      last.focus();
	      event.preventDefault();
	    }
	  };

	  toggleListener.call(this, this.elements.container, 'keydown', trap, toggle, false);
	}
function trapFocus() {
	  var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
	  var toggle = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

	  if (!is$1.element(element)) {
	    return;
	  }

	  var focusable = getElements.call(this, 'button:not(:disabled), input:not(:disabled), [tabindex]');
	  var first = focusable[0];
	  var last = focusable[focusable.length - 1];

	  var trap = function trap(event) {
	    
	    if (event.key !== 'Tab' || event.keyCode !== 9) {
	      return;
	    } 


	    var focused = document.activeElement;

	    if (focused === last && !event.shiftKey) {
	      
	      first.focus();
	      event.preventDefault();
	    } else if (focused === first && event.shiftKey) {
	      
	      last.focus();
	      event.preventDefault();
	    }
	  };

	  toggleListener.call(this, this.elements.container, 'keydown', trap, toggle, false);
	}
function trapFocus ( ) { var element = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : null ; var toggle = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : false ; if ( ! is$1 . element ( element ) ) { return ; } var focusable = getElements . call ( this , 'button:not(:disabled), input:not(:disabled), [tabindex]' ) ; var first = focusable [ 0 ] ; var last = focusable [ focusable . length - 1 ] ; var trap = function trap ( event ) { // Bail if not tab key or not fullscreen if ( event . key !== 'Tab' || event . keyCode !== 9 ) { return ; } // Get the current focused element var focused = document . activeElement ; if ( focused === last && ! event . shiftKey ) { // Move focus to first element that can be tabbed if Shift isn't used first . focus ( ) ; event . preventDefault ( ) ; } else if ( focused === first && event . shiftKey ) { // Move focus to last element that can be tabbed if Shift is used last . focus ( ) ; event . preventDefault ( ) ; } } ; toggleListener . call ( this , this . elements . container , 'keydown' , trap , toggle , false ) ; }
Trap focus inside container
Trap focus inside container