Search code examples
extjsmodal-dialogextjs4.1

How to close modal window extjs when clicking on mask?


If I create a modal window:

Ext.define('myWindow', {
    extend: 'Ext.Container',
    alias: 'widget.myWindow',
    floating: true,
    modal: true,
    listeners:
        'onMaskClick???': { close the window }
    .....
}

How do I know when a user has clicked on the mask outside the window? In Sench Touch, there is a config hideOnMaskTap that lets me specify. What is the event/config for extJS?


Solution

  • Tramway's case (sort of) works on modal or non modal windows. But not in case child components like the boundlist of a combobox float outside the windows boundaries.

    However if you use modal windows anyway you can listen for a click event on the mask like this.

    Ext.define('myWindow', {
        extend: 'Ext.window.Window',
        alias: 'widget.myWindow',
        floating: true,
        modal: true,
    
        initComponent: function () {
            var me = this;
            me.callParent(arguments);
            me.mon(Ext.getBody(), 'click', function(el, e){
                me.close(me.closeAction);
            }, me, { delegate: '.x-mask' });
        }
    });