* Focuses the provided element. If the element is not focusable, it will add a tabIndex * attribute to forcefully focus it. The attribute is removed after focus is moved. * @param element The element to focus.
(element: HTMLElement, options?: FocusOptions)
| 217 | * @param element The element to focus. |
| 218 | */ |
| 219 | private _forceFocus(element: HTMLElement, options?: FocusOptions) { |
| 220 | if (!this._interactivityChecker.isFocusable(element)) { |
| 221 | element.tabIndex = -1; |
| 222 | // The tabindex attribute should be removed to avoid navigating to that element again |
| 223 | this._ngZone.runOutsideAngular(() => { |
| 224 | const callback = () => { |
| 225 | deregisterBlur(); |
| 226 | deregisterMousedown(); |
| 227 | element.removeAttribute('tabindex'); |
| 228 | }; |
| 229 | |
| 230 | const deregisterBlur = this._renderer.listen(element, 'blur', callback); |
| 231 | const deregisterMousedown = this._renderer.listen(element, 'mousedown', callback); |
| 232 | }); |
| 233 | } |
| 234 | element.focus(options); |
| 235 | } |
| 236 | |
| 237 | /** |
| 238 | * Focuses the first element that matches the given selector within the focus trap. |
no test coverage detected