Stop the sign-in page jumping when the iOS keyboard opens

A sign-in page already fills the screen, so it no longer shrinks itself
to the area above an on-screen keyboard. On iOS that resize fought the
browser's own pan to the focused field and the form moved up and down
as the keyboard opened. Dialogs still fit above the keyboard.
This commit is contained in:
Nariman Jelveh committed 2026-11-06 15:40:36 -07:00
1 parent 9758ada36e
commit cce9718b45
3 files changed
+14 -2

No files matched your search

+3
View File
@@ -201,6 +201,9 @@ export default function openAuthFlow ({ page = false, dismissable = ! page, clos
const { $overlay, $dialog, close: closeOverlay, isClosed } = mountDashboardOverlay({
html: h,
// A page already fills the screen. Resizing it under iOS's own pan to
// the focused field makes the form jump up and down as the keyboard opens.
fitKeyboard: ! as_page,
canDismiss: (via) => dismissable
&& (via === 'close' || (! busy && (via !== 'backdrop' || closeOnBackdrop))),
onDismiss: () => {
+4 -2
View File
@@ -72,9 +72,11 @@ export function bindBackdropDismiss ($overlay, isBackdrop, dismiss) {
* overlay, after it has closed. Not called for `close()`.
* @param {(via: 'escape'|'close'|'backdrop') => boolean} [opts.canDismiss]
* Consulted before each dismissal; returning false keeps the overlay up.
* @param {boolean} [opts.fitKeyboard] Shrink to the part of the screen an
* on-screen keyboard leaves visible. Defaults to true.
* @returns {{ $overlay: jQuery, $dialog: jQuery, close: () => void, isClosed: () => boolean }}
*/
export default function mountDashboardOverlay ({ html, $container, returnFocusTo, onDismiss, canDismiss }) {
export default function mountDashboardOverlay ({ html, $container, returnFocusTo, onDismiss, canDismiss, fitKeyboard = true }) {
const $root = $container && $container.length ? $container : $('body');
const ns = `.dashboard-overlay-${++overlay_seq}`;
const el_previous_focus = document.activeElement;
@@ -87,7 +89,7 @@ export default function mountDashboardOverlay ({ html, $container, returnFocusTo
// iOS lays its keyboard over the page rather than resizing it, which
// would leave a bottom sheet's fields and buttons underneath. Pin the
// overlay to the part of the screen that is still visible.
const viewport = window.visualViewport;
const viewport = fitKeyboard ? window.visualViewport : null;
const fitToViewport = () => {
const covered = window.innerHeight - viewport.height - viewport.offsetTop;
const pinned = covered > 1 || viewport.offsetTop > 1;
@@ -150,6 +150,13 @@ describe('mountDashboardOverlay', () => {
close();
expect(window.visualViewport.removeEventListener).toHaveBeenCalledWith('resize', listeners.resize);
});
it('leaves its size alone under a keyboard when told not to fit it', () => {
window.visualViewport = { height: window.innerHeight, offsetTop: 0, addEventListener: vi.fn(), removeEventListener: vi.fn() };
const { close } = mountDashboardOverlay({ html: card, fitKeyboard: false });
expect(window.visualViewport.addEventListener).not.toHaveBeenCalled();
close();
});
});
describe('bindBackdropDismiss', () => {