MzpMenu.onFocusOut = function()

in assets/js/protocol/menu.js [141:159]


MzpMenu.onFocusOut = function() {
    /**
     * Note: 'this' needs to reference the active DOM node, so here `focusOut` is not
     * an arrow (=>) function, since that would lexically bind `this` to `window`.
     */
    const self = this;

    /**
     * After an element loses focus, `document.activeElement` will always be `body` before
     * moving to the next element. A `setTimeout` of `0` circumvents this issue as it
     * re-queues the JavaScript to run at the end of the current execution.
     */
    setTimeout(() => {
        // If the menu is open and the newly focused element is not a child, then call close().
        if (!self.contains(document.activeElement) && self.classList.contains('mzp-is-selected')) {
            MzpMenu.close();
        }
    }, 0);
};