Проблема с контекстным меню в office-fabric-ui при втором нажатии

Мы работаем над Office UI Fabric JS 1.2.0. Проблема заключается в том, что контекстное меню имеет элементы подменю. Когда вы открываете второй уровень, а затем щелкаете в любом месте меню, меню первого уровня закрывается, а второе меню перестраивается в верхний левый угол страницы. Мы не смогли найти решение и в следующей версии ткани.


person Vishnu    schedule 19.07.2017    source источник


Ответы (1)


Проблема решается после переопределения двух методов из fabric.js из ContextualHost следующим образом:

fabric.ContextualHost.prototype.disposeModal = function () {
    if (fabric.ContextualHost.hosts.length > 0) {
        window.removeEventListener("resize", this._resizeAction, false);
        document.removeEventListener("click", this._dismissAction, true);
        document.removeEventListener("keyup", this._handleKeyUpDismiss, true);
        this._container.parentNode.removeChild(this._container);
        if (this._disposalCallback) {
            this._disposalCallback();
        }
        // Dispose of all ContextualHosts
        var index = fabric.ContextualHost.hosts.indexOf(this);
        fabric.ContextualHost.hosts.splice(index, 1);

        //Following is original code removed
        //var i = ContextualHost.hosts.length;
        //while (i--) {
        //    ContextualHost.hosts[i].disposeModal();
        //    ContextualHost.hosts.splice(i, 1);
        //}
    }
};

fabric.ContextualHost.prototype._dismissAction = function (e) {

    var i = fabric.ContextualHost.hosts.length;
    while (i--) { //New added
        var currentHost = fabric.ContextualHost.hosts[i];
        if (!currentHost._container.contains(e.target) && e.target !== this._container) {
            if (currentHost._children !== undefined) {
                var isChild_1 = false;
                currentHost._children.map(function (child) {
                    if (child !== undefined) {
                        isChild_1 = child.contains(e.target);
                    }
                });
                if (!isChild_1) {
                    currentHost.disposeModal();
                }
            }
            else {
                currentHost.disposeModal();
            }
        }
    }
};

Надеюсь, что этот вопрос + ответ поможет кому-то, кто хочет переопределить исходный код Fabric.js.

person Vishnu    schedule 19.07.2017