handleFocusTrap = (modal) => {
    const dom = globalObj._dom;
    const state = globalObj._state;

    /**
     * @param {HTMLDivElement} modal
     * @param {HTMLElement[]} focusableElements
     */
    const trapFocus = (modal) => {
        const isConsentModal = modal === dom._cm;

        const scope = state._userConfig.disablePageInteraction
            ? dom._htmlDom
            : isConsentModal
                ? dom._ccMain
                : dom._htmlDom;

        const getFocusableElements = () => isConsentModal
            ? state._cmFocusableElements
            : state._pmFocusableElements;

        const isModalVisible = () => isConsentModal
            ? state._consentModalVisible && !state._preferencesModalVisible
            : state._preferencesModalVisible;

        addEvent(scope, 'keydown', (e) => {
            if (e.key !== 'Tab' || !isModalVisible())
                return;

            const currentActiveElement = getActiveElement();
            const focusableElements = getFocusableElements();

            if (focusableElements.length === 0)
                return;

            /**
             * If reached natural end of the tab sequence => restart
             * If current focused element is not inside modal => focus modal
             */
            if (e.shiftKey) {
                if (currentActiveElement === focusableElements[0] || !modal.contains(currentActiveElement)) {
                    preventDefault(e);
                    focus(focusableElements[1]);
                }
            } else {
                if (currentActiveElement === focusableElements[1] || !modal.contains(currentActiveElement)) {
                    preventDefault(e);
                    focus(focusableElements[0]);
                }
            }
        }, true);
    };

    trapFocus(modal);
}
Trap focus inside modal and focus the first
focusable element of current active modal
@param {HTMLDivElement} modal