41

I'm using the jQuery UI dialog with modal=true. In Chrome and Safari, this disables scrolling via the scroll bar and cursor keys (scrolling with the mouse wheel and page up/down still works).

This is a problem if the dialog is too tall to fit on one page - users on a laptop get frustrated.

Someone raised this three months ago on the jQuery bug tracker - http://dev.jqueryui.com/ticket/4671 - it doesn't look like fixing it is a priority. :)

So does anyone:

  1. have a fix for this?
  2. have a suggested workaround that would give a decent usability experience?

I'm experimenting with mouseover / scrollto on bits of the form, but it's not a great solution :(

EDIT : props to Rowan Beentje (who's not on SO afaict) for finding a solution to this. jQuery UI prevents scrolling by capturing the mouseup / mousedown events. So the code below seems to fix it:

$("dialogId").dialog({
 open: function(event, ui) {
 window.setTimeout(function() {
 jQuery(document).unbind('mousedown.dialog-overlay')
 .unbind('mouseup.dialog-overlay');
 }, 100);
 },
 modal: true
});

Use at own risk, I don't know what other unmodal behaviour unbinding this stuff might allow.

tw16
29.7k7 gold badges65 silver badges64 bronze badges
asked Oct 24, 2009 at 10:44

9 Answers 9

38

You can use this code : jquery.ui.dialog.patch.js

It solved the problem for me. Hope this is the solution that you're looking for.

answered Oct 12, 2011 at 13:22
3
  • 3
    The bug has been fixed in jquery ui version 1.10.0 (dev.jqueryui.com/ticket/4671) Commented Feb 9, 2013 at 14:12
  • This should be marked as the correct solution. Like Nitin said: This should only be needed for people using jqueryui before version 1.10.0 Commented Jul 17, 2013 at 14:46
  • Works for everything I've tried except Android browser. Commented Mar 14, 2014 at 9:31
7
+100

I agree with the previous posters in that if the dialog is not working for you, it may be good to rethink your design. However, I can offer a suggestion.

Could you put the dialog content inside a scrollable div? That way instead of the whole page needing to scroll, just the content inside the div would need to scroll. This workaround should be pretty easy to accomplish too.

answered Nov 2, 2009 at 15:32
1
  • I used a scrollable div in one of my recent projects. It appears to work fine for all but Safari on OS X Lion (works fine with Safari on Windows 7 and OS X Snow Leopard, though). For Lion, the scrolling works, but the scroll bar isn't visible. I ended up here looking for a solution to that issue. Commented Jan 9, 2012 at 16:10
2

I workaround this situation by disabling dialog modal mode and showing overlay manually:

function showPopup()
{
 //...
 // actionContainer - is a DIV for dialog
 if ($.browser.safari == true)
 {
 // disable modal mode
 $("#actionContainer").dialog('option', 'modal', false);
 // show overlay div manually
 var tempDiv = $("<div id='tempOverlayDiv'></div>");
 tempDiv.css("background-color", "#000");
 tempDiv.css("opacity", "0.2");
 tempDiv.css("position", "absolute");
 tempDiv.css("left", 0);
 tempDiv.css("top", 0);
 tempDiv.css("width", $(document).width());
 tempDiv.css("height", $(document).height());
 $("body").append(tempDiv);
 }
 // remove overlay div on dialog close
 $("#actionContainer").bind('dialogclose', function(event, ui) {
 $("#tempOverlayDiv").remove(); 
 });
 //...
}
answered Aug 26, 2010 at 17:34
2

There is a workaround that unbind the binded event. This adds the following in the open: event of the dialog :

$("#longdialog").dialog({
 modal:true,
 open: function (event, ui) { window.setTimeout(function () {
 jQuery(document).unbind('mousedown.dialog-overlay').unbind('mouseup.dialog-overlay'); }, 100);
 }
});

This works ... but this is ugly

--from https://github.com/jquery/jquery-ui/pull/230#issuecomment-3630449

Worked like a charm in my case.

answered Oct 16, 2012 at 12:40
1
  • downvote for? atleast don't mislead others looking for solution! This really works! Commented Oct 17, 2012 at 5:43
1

I believe having too big dialogs is against your 'decent usability experience' requirement. Even if you didn't have to have a workaround due to the jQuery UI Dialog bug, I'd get rid of such big dialogs. Anyway, I do understand there may be some 'extreme' cases in which you need to adapt, so...

That said, it would certainly help if you attached some screenshot - you're asking a question about a design, but we can't see it. But I understand you might not be able/willing to show the contents of it so that's fine. These are my blind guesses; hope you find them useful:

  • Try a different layout for your dialog. If you do this, do it for all dialogs, not just the ones you're having problem with (users don't like to learn many different UIs).
  • If you can't find a different layout, try widening your dialog first. IF you have many options to choose from, you might find a good solution by dividing them in two columns.
  • Knowing you're already using jQuery UI, try using tabs. If you have too many options, a tabbed panel is usually a good solution - users are 'used' to that widget.
  • You talked about 'items' in the dialog, but we don't know what an item is. Is it possible at all to show them in a 'summarized' way such as a small list at the left and an expanded view at the right when you click on them? For example, having a list with the items titles at the left, and when you click them you get the full display on the right.

Without being able to see the design, I guess that's as far as I can go.

answered Nov 2, 2009 at 14:06
1
  • If you're morbidly curious, the modal in question is at echobazaar.failbettergames.com , but it takes a login and a couple of minutes to see it. I'll take a look at your other suggestions in the medium term - thanks. Commented Nov 2, 2009 at 21:35
1

While I agree with, the folks in the party of not making a dialog that is bigger than the viewport, I think there are cases where scrolling may be necessary. A dialog might look very good in a resolution greater the 1024 x 768, but anything less looks crunched. Or say for instance you never want a dialog to show up over the header of your site. In my case I have ads that occassionally have flash z-index problems, so I never want dialogs to show above them. Finally, it is bad in general to take away any sort of common control, like scrolling, away from the user. This is a problem separate from how big the dialog is.

I would be interested in knowing why the those mousedown and mouseup events are there in the first place.

I tried the solution that alexis.kennedy provided and it works break without breaking anything that I can see in any browser.

answered May 15, 2010 at 21:15
1

This is a bug that has been since fixed: http://bugs.jqueryui.com/ticket/4671

answered Jan 31, 2013 at 18:10
0

Did you try my extension to the Dialog? http://plugins.jquery.com/project/jquery-framedialog

answered Jun 16, 2010 at 20:47
0

Use the code below. It will work fine.

$("dialogId").dialog({
 open: function(event, ui) {
 window.setTimeout(function() {
 jQuery(document).unbind('mousedown.dialog-overlay')
 .unbind('mouseup.dialog-overlay');
 }, 100);
 },
 modal: true,
 safariBrowser: (function( ,ドル undefined ) {
 if ($.ui && $.ui.dialog) {
 $.ui.dialog.overlay.events = $.map('focus,keydown,keypress'.split(','), function(event) { return event + '.dialog-overlay'; }).join(' ');
 }
 }(jQuery))
});
Colwin
2,6833 gold badges25 silver badges26 bronze badges
answered Jun 16, 2017 at 7:08
1
  • ".dialog-overlay" change to your dialog overlay class name Commented Jun 16, 2017 at 7:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.