qTip2 / qTip2

qTip2 - Pretty powerful tooltips
MIT License
2k stars 465 forks source link

modal stealing focus from select2 search input #841

Open stSaHiB opened 6 years ago

stSaHiB commented 6 years ago

hi,

I'm using select2 inside modal qtips. Select2 (and other skripts) is apending its dropdown to body. Within the dropdown there is a search field, which can't get focus due to the stealFocus(event) function of the modal plugin, which is stealing focus from everything that is not within the current tooltip.

I helped myself (very quick, very dirty) whith this new modal option (which is defaulted to FALSE):

show:{
    modal:{
        on:true,
        blur:false,
        stealNotFrom:'.select2-search__field'
    }
},
function stealFocus(event){
    if(!elem.is(':visible')){ return; }

    var target=$(event.target),
        tooltip=current.tooltip,
        container=target.closest(SELECTOR),
        targetOnTop;

    //Get back! Oh, get back! Don't you touch my stereo, these are my records! 
    if(current.options.show.modal.stealNotFrom!==FALSE){
        if(target.is(current.options.show.modal.stealNotFrom)){ return; }
    }

    targetOnTop=container.length<1?FALSE:
        parseInt(container[0].style.zIndex,10)>parseInt(tooltip[0].style.zIndex,10);

    if(!targetOnTop && target.closest(SELECTOR)[0]!==tooltip[0]){
        focusInputs(target);
    }
}

I'm not sure if I'm missing an option already build in, because no one seems to have the same problem, while I bet many users use scripts like select2 or selectize, or... But if there is no option yet, I would suggest (and appreciate) to build in the option, which allows you to specify a selector for items which are excluded from stealFocus.