Phones: no AutoFill bar over text boxes, steadier scrolling above the keyboard

- Text boxes say autocomplete="off" (the forum's in the markup, any other
  textarea when it gets the focus), so iOS Safari does not lay its AutoFill
  bar (passwords, cards, addresses) over them.
- KeyboardSafe scrolls at once instead of smoothly (the browser's own
  scroll cut the smooth one short on iOS), once more when that has
  settled, and keeps a little more room above the keyboard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-26 17:14:45 +00:00
co-authored by Claude Opus 5.5
parent c07c7b68bf
commit a622d30b39
4 changed files with 26 additions and 11 deletions
@@ -55,6 +55,7 @@ export default async function SearchPage({ searchParams }: { searchParams: Promi
id="fsearch-q"
name="q"
type="search"
autoComplete="off"
className="inp"
defaultValue={q}
placeholder="Mit keresel? Például: alvás, telihold, gyász"
@@ -187,6 +187,7 @@ export function NewThreadForm({
onChange={(e) => withEmoji(e, setTitle)}
maxLength={120}
required
autoComplete="off"
placeholder="Adj címet a szálnak…"
/>
<label htmlFor="fnew-body" className="sr-only">
@@ -200,6 +201,7 @@ export function NewThreadForm({
onChange={(e) => withEmoji(e, setBody)}
maxLength={10000}
required
autoComplete="off"
placeholder={intent === "listen" ? "Írd le, ami benned van…" : "Írd le a gondolataidat…"}
/>
<div className="fnew-foot">
@@ -27,7 +27,9 @@ function typedInto(el: Element | null): el is HTMLElement {
* menu and other fixed bars step aside), `--vv-top` and `--vv-height` give
* the part of the screen the keyboard leaves free (for full-screen panels),
* and the field, with its send button when the form is small, is scrolled
* into that part.
* into that part. A text box gets `autocomplete="off"` unless it says
* otherwise, so iOS Safari does not lay its AutoFill bar (passwords, cards,
* addresses) over it.
*/
export function KeyboardSafe() {
useEffect(() => {
@@ -35,6 +37,7 @@ export function KeyboardSafe() {
const root = document.documentElement;
const vv = window.visualViewport;
let timer: number | undefined;
let again: number | undefined;
let closing: number | undefined;
const measure = () => {
@@ -51,26 +54,33 @@ export function KeyboardSafe() {
const form = el.closest("form");
const target = form && form.getBoundingClientRect().height < height * 0.6 ? form : el;
const rect = target.getBoundingClientRect();
const free = { top: top + 12, bottom: top + height - 12 };
if (rect.bottom > free.bottom) {
window.scrollBy({ top: Math.min(rect.bottom - free.bottom, rect.top - free.top), behavior: "smooth" });
} else if (rect.top < free.top) {
window.scrollBy({ top: rect.top - free.top, behavior: "smooth" });
}
const free = { top: top + 12, bottom: top + height - 16 };
let delta = 0;
if (rect.bottom > free.bottom) delta = Math.min(rect.bottom - free.bottom, rect.top - free.top);
else if (rect.top < free.top) delta = rect.top - free.top;
// At once: a smooth scroll would be cut short by the browser's own one.
if (Math.abs(delta) > 2) window.scrollBy({ top: delta, behavior: "instant" });
};
// After the keyboard has slid up, and again whenever the free part changes.
// After the keyboard has slid up (and once more when the browser's own
// scrolling has settled), and whenever the free part changes.
const later = (ms: number) => {
window.clearTimeout(timer);
window.clearTimeout(again);
timer = window.setTimeout(reveal, ms);
again = window.setTimeout(reveal, ms + 450);
};
const onFocusIn = (e: FocusEvent) => {
if (!typedInto(e.target as Element)) return;
const field = e.target as Element;
if (field instanceof HTMLTextAreaElement && !field.hasAttribute("autocomplete")) {
field.setAttribute("autocomplete", "off");
}
if (!typedInto(field)) return;
window.clearTimeout(closing);
root.classList.add("kb-open");
measure();
later(350);
later(300);
};
const onFocusOut = () => {
// Moving to another field keeps it open.
@@ -82,7 +92,7 @@ export function KeyboardSafe() {
const onViewport = () => {
if (!root.classList.contains("kb-open")) return;
measure();
later(120);
later(150);
};
document.addEventListener("focusin", onFocusIn);
@@ -91,6 +101,7 @@ export function KeyboardSafe() {
vv?.addEventListener("scroll", measure);
return () => {
window.clearTimeout(timer);
window.clearTimeout(again);
window.clearTimeout(closing);
document.removeEventListener("focusin", onFocusIn);
document.removeEventListener("focusout", onFocusOut);
@@ -122,6 +122,7 @@ export function Composer({
if (e.key === "Escape") setSuggest(null);
}}
maxLength={10000}
autoComplete="off"
autoFocus={autoFocus}
aria-autocomplete={mentions ? "list" : undefined}
/>