Atlas91
Atlas91

Reputation: 5904

Ukit modal prevent close on escape button

I'm using Uikit with Angularjs and i need create possibly a directive that prevent the closing of the Modal when i press esc button. I tried with this way:

mainApp.directive('ngEsc', function () {
    return function (scope, element, attrs) {
        element.bind("keydown keypress keyup", function (event) {
            if(event.which === 27) {
                event.preventDefault();
            }
        });
    };
});

And then put the directive on the modal

Test modal

But it still closes. Is there any other way?

Upvotes: 3

Views: 3213

Answers (3)

Phebian Chukwurah
Phebian Chukwurah

Reputation: 71

Below is how I fixed this issue in my angular 7 project;

uikit.modal("#modalR", { bgClose: false, escClose: false, modal: false, keyboard:false}).show(this.data)

for more information please visit link below https://github.com/uikit/uikit/blob/develop/src/js/core/modal.js#L15:L21

Upvotes: 6

Jose Silva
Jose Silva

Reputation: 51

Have you tried to use the option keyboard:false?

UIkit.modal("#modal element", {bgclose: false, keyboard:false}).show();

It worked in my case.

You can see the core of modal uikit as well: modal.js

Upvotes: 4

alexey
alexey

Reputation: 801

You can try use "return false" instead of preventDefault:

mainApp.directive('ngEsc', function () {
    return function (scope, element, attrs) {
        element.bind("keydown keypress keyup", function (event) {
            if(event.which === 27) {
                return false;
            }
        });
    };
});

Upvotes: 0

Related Questions