material icon indicating copy to clipboard operation
material copied to clipboard

md-dialog wrong position on keyboard close (Safari Mobile / iOS 8)

Open cpae opened this issue 11 years ago • 1 comments

When iOS Safari opens the keyboard, the page scrolls up to focus the input/textbox/... .

After closing the Keyboard, the dialog retains scrolled up, so there is a white space at the bottom of the backdrop.

If you continue to reopen the keyboard and close the dialog moves even further up.

Possible Fix (add to MdDialogProvider onShow-function):

// FIX BEGIN
function iOSKeyboardCloseScrollPositionFix(scrollPosition, e) {
    var isIOS = navigator.userAgent.match(/iOS|iPad|iPhone|iPod/g) || navigator.platform.match(/iOS|iPad|iPhone|iPod/g) ? true : false;
    if (isIOS) {
        if ($("md-dialog").is(":visible")) {
            $(document).scrollTop(scrollPosition);
        }


    }
}
// FIX END

// On show method for dialogs
function onShow(scope, element, options) {
    angular.element($document[0].body).addClass('md-dialog-is-showing');

    // FIX BEGIN
    var initialScrollPosition = $(document).scrollTop();
    $(document).on('focusout.mddialogiosfixes', $.proxy(iOSKeyboardCloseScrollPositionFix, null, initialScrollPosition));
    // FIX END

    ...
}

// On remove function for all dialogs
function onRemove(scope, element, options) {
    angular.element($document[0].body).removeClass('md-dialog-is-showing');

    // FIX BEGIN                    
    $(document).off('.mddialogiosfixes');
    // FIX END

    ...
}

note: can also be fixed by using a fixed layout with absolute scrolling containers, see https://github.com/angular/material/issues/3079#issuecomment-110362949

cpae avatar Jul 06 '15 19:07 cpae

+1.

And, if you are showing a dialog when a button is clicked, there is an easier-but-not-so-elegant workaround: Delay dialog showing by a short time, like 500ms, to allow the keyboard hiding.

cnjsstong avatar Jul 17 '15 05:07 cnjsstong