fix(native): a field on a page as tall as the screen comes up above the keyboard on iOS

The login on an iPhone scrolls in no pane of its own, and the keyboard plugin
holds the body's height, so the page had nothing to scroll by and the password
field stayed under the keyboard, most of all with an error shown above it. Such
a page now gets room as tall as the keyboard at its end and scrolls the field
above it; the room goes with the keyboard.
This commit is contained in:
Maurice
2026-11-09 23:12:27 +01:00
parent 034cfb539a
commit 1cdde6e9a4
2 changed files with 40 additions and 1 deletions
+17 -1
View File
@@ -29,6 +29,13 @@ interface KeyboardEvents {
/** The pane given room for the keyboard, and what its bottom padding was before. */
let padded: { pane: HTMLElement; before: string } | null = null;
/**
* The room at the end of a page that scrolls in no pane of its own, such as the
* login: as tall as the screen, it has nothing to scroll by, and padding on the
* body does not help while the keyboard plugin holds the body's height.
*/
let pageRoom: HTMLElement | null = null;
function scrollingPane(field: HTMLElement): HTMLElement | null {
for (let node = field.parentElement; node; node = node.parentElement) {
const overflow = getComputedStyle(node).overflowY;
@@ -48,7 +55,14 @@ export function revealFocusedField(keyboardHeight: number, doc: Document = docum
const pane = scrollingPane(field);
if (!pane) {
field.scrollIntoView({ block: 'center', behavior: 'smooth' });
if (!pageRoom) {
releaseRoom();
pageRoom = doc.createElement('div');
pageRoom.setAttribute('aria-hidden', 'true');
pageRoom.style.height = `${keyboardHeight}px`;
doc.body.appendChild(pageRoom);
}
view?.scrollBy({ top: box.bottom - (visibleBottom - AIR), behavior: 'smooth' });
return;
}
if (!padded || padded.pane !== pane) {
@@ -61,6 +75,8 @@ export function revealFocusedField(keyboardHeight: number, doc: Document = docum
/** Takes the room for the keyboard away again. */
export function releaseRoom(): void {
pageRoom?.remove();
pageRoom = null;
if (!padded) return;
padded.pane.style.paddingBottom = padded.before;
padded = null;