MCPcopy Index your code
hub / github.com/microsoft/SandDance / focusAsync

Function focusAsync

docs/app/js/sanddance-app.js:24702–24727  ·  view source on GitHub ↗
(element)

Source from the content-addressed store, hash-verified

24700}
24701var targetToFocusOnNextRepaint = undefined;
24702function focusAsync(element) {
24703 if (element) {
24704 // An element was already queued to be focused, so replace that one with the new element
24705 if (targetToFocusOnNextRepaint) {
24706 targetToFocusOnNextRepaint = element;
24707 return;
24708 }
24709 targetToFocusOnNextRepaint = element;
24710 var win = (0, _getWindow.getWindow)(element);
24711 if (win) // element.focus() is a no-op if the element is no longer in the DOM, meaning this is always safe
24712 win.requestAnimationFrame(function() {
24713 var focusableElement = targetToFocusOnNextRepaint;
24714 // We are done focusing for this frame, so reset the queued focus element
24715 targetToFocusOnNextRepaint = undefined;
24716 if (focusableElement) {
24717 if (focusableElement.getAttribute && focusableElement.getAttribute(IS_FOCUSABLE_ATTRIBUTE) === "true") // Normally, a FocusZone would be responsible for setting the tabindex values on all its descendants.
24718 // However, even this animation frame callback can pre-empt the rendering of a FocusZone's child elements,
24719 // so it may be necessary to set the tabindex directly here.
24720 {
24721 if (!focusableElement.getAttribute("tabindex")) focusableElement.setAttribute("tabindex", "0");
24722 }
24723 focusableElement.focus();
24724 }
24725 });
24726 }
24727}
24728function getFocusableByIndexPath(parent, path) {
24729 var element = parent;
24730 for(var _i = 0, path_1 = path; _i < path_1.length; _i++){

Callers 1

focusFirstChildFunction · 0.85

Calls 1

focusMethod · 0.45

Tested by

no test coverage detected