(props)
| 33109 | var FocusTrapZone = /** @class */ function(_super) { |
| 33110 | (0, _tslib.__extends)(FocusTrapZone1, _super); |
| 33111 | function FocusTrapZone1(props) { |
| 33112 | var _this = _super.call(this, props) || this; |
| 33113 | _this._root = _react.createRef(); |
| 33114 | _this._firstBumper = _react.createRef(); |
| 33115 | _this._lastBumper = _react.createRef(); |
| 33116 | _this._hasFocus = false; |
| 33117 | _this._onRootFocus = function(ev) { |
| 33118 | if (_this.props.onFocus) _this.props.onFocus(ev); |
| 33119 | _this._hasFocus = true; |
| 33120 | }; |
| 33121 | _this._onRootBlur = function(ev) { |
| 33122 | if (_this.props.onBlur) _this.props.onBlur(ev); |
| 33123 | var relatedTarget = ev.relatedTarget; |
| 33124 | if (ev.relatedTarget === null) // In IE11, due to lack of support, event.relatedTarget is always |
| 33125 | // null making every onBlur call to be "outside" of the ComboBox |
| 33126 | // even when it's not. Using document.activeElement is another way |
| 33127 | // for us to be able to get what the relatedTarget without relying |
| 33128 | // on the event |
| 33129 | relatedTarget = _this._getDocument().activeElement; |
| 33130 | if (!(0, _utilities1.elementContains)(_this._root.current, relatedTarget)) _this._hasFocus = false; |
| 33131 | }; |
| 33132 | _this._onFirstBumperFocus = function() { |
| 33133 | _this._onBumperFocus(true); |
| 33134 | }; |
| 33135 | _this._onLastBumperFocus = function() { |
| 33136 | _this._onBumperFocus(false); |
| 33137 | }; |
| 33138 | _this._onBumperFocus = function(isFirstBumper) { |
| 33139 | if (_this.props.disabled) return; |
| 33140 | var currentBumper = isFirstBumper === _this._hasFocus ? _this._lastBumper.current : _this._firstBumper.current; |
| 33141 | if (_this._root.current) { |
| 33142 | var nextFocusable = isFirstBumper === _this._hasFocus ? (0, _utilities1.getLastTabbable)(_this._root.current, currentBumper, true, false) : (0, _utilities1.getFirstTabbable)(_this._root.current, currentBumper, true, false); |
| 33143 | if (nextFocusable) { |
| 33144 | if (_this._isBumper(nextFocusable)) // This can happen when FTZ contains no tabbable elements. |
| 33145 | // focus will take care of finding a focusable element in FTZ. |
| 33146 | _this.focus(); |
| 33147 | else nextFocusable.focus(); |
| 33148 | } |
| 33149 | } |
| 33150 | }; |
| 33151 | _this._onFocusCapture = function(ev) { |
| 33152 | if (_this.props.onFocusCapture) _this.props.onFocusCapture(ev); |
| 33153 | if (ev.target !== ev.currentTarget && !_this._isBumper(ev.target)) // every time focus changes within the trap zone, remember the focused element so that |
| 33154 | // it can be restored if focus leaves the pane and returns via keystroke (i.e. via a call to this.focus(true)) |
| 33155 | _this._previouslyFocusedElementInTrapZone = ev.target; |
| 33156 | }; |
| 33157 | _this._forceFocusInTrap = function(ev) { |
| 33158 | if (_this.props.disabled) return; |
| 33159 | if (FocusTrapZone1._focusStack.length && _this === FocusTrapZone1._focusStack[FocusTrapZone1._focusStack.length - 1]) { |
| 33160 | var focusedElement = _this._getDocument().activeElement; |
| 33161 | if (!(0, _utilities1.elementContains)(_this._root.current, focusedElement)) { |
| 33162 | _this.focus(); |
| 33163 | _this._hasFocus = true; // set focus here since we stop event propagation |
| 33164 | ev.preventDefault(); |
| 33165 | ev.stopPropagation(); |
| 33166 | } |
| 33167 | } |
| 33168 | }; |
nothing calls this directly
no test coverage detected