magento2: Modal UI: clickableOverlay option doesn't work

Preconditions

  1. Magento 2.1.2

Steps to reproduce

  1. Go into any template and create a modal widget with this code:
require(['Magento_Ui/js/modal/modal'], function(modal) {
  $('#some-element').click(function(e) {
    e.preventDefault();
    $('<p>Overlay content</p>').modal().modal('openModal');
  });
});
  1. Click on $('#some-element') to show the overlay.
  2. Click on the overlay (shadow).

Expected result

  1. According to the documentation, the default clickableOverlay value is true, which means “Close the modal window when a user clicks on the overlay”.

Actual result

  1. Nothing happens (i.e., the overlay does not close). Even when you manually specify the option, it doesn’t work:

$('<p>Overlay content</p>').modal({ clickableOverlay: true }).modal('openModal');

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 11
  • Comments: 24 (12 by maintainers)

Commits related to this issue

Most upvoted comments

We created a workaround for this issue in a custom theme using a RequireJS mixin by adding the following files:

app/design/frontend/<VENDOR>/<THEME>/Magento_Ui/web/js/model/modal-mixin.js

define([
    'jquery',
    'mage/utils/wrapper'
], function ($, wrapper) {
    'use strict';

    return function (modal) {

        modal.prototype.openModal = wrapper.wrap(modal.prototype.openModal, function(original) {

            var result = original();
            $('.' + this.options.overlayClass).appendTo('.modal-popup._show');
            //Setting z-index of inner-wrap to 900 so that it is actually clickable and not hiding behind the overlay
            $('.modal-inner-wrap').css('z-index', 900);
            return result;
        });

        return modal;
    };
});

app/design/frontend/<VENDOR>/<THEME>/requirejs-config.js

var config = {
    config: {
        mixins: {
            'Magento_Ui/js/modal/modal': {
                'Magento_Ui/js/model/modal-mixin': true
            }
        }
    }
};

See this great article by Alan Storm for info on M2’s RequireJS Mixins: http://alanstorm.com/the-curious-case-of-magento-2-mixins/

Hello, made it work by applying a small css fix (if anyone is still interested):

.modal-popup {
    pointer-events: none;
    touch-action: none;
}

This is not fixed in 2.2. The CSS for pointer-events is present, but modal.js doesn’t actually handle a click on the overlay. clickableOverlay is present in the default options, but it’s not found anywhere else in the file (meaning it’s not used). Comparing 2.1, 2.2, and 2.3, the _createOverlay method is lacking lines in 2.2.

@BB-000 Yeah, we discovered some issues with the code I posted previously and have since refactored and moved the code into a standalone extension called ClassyLlama_ModalEnhancements. I’ve attached it to this comment. Use at your own risk.

ClassyLlama_ModalEnhancements.zip

.modal-popup { pointer-events: none; }

I do not see this fix in the Magento 2.2.5 release

@erikhansen Unfortunately for me that fix works on desktop (popup) but breaks mobile (slide) modals…