· 3 min read

Mobile typing needs a different focus policy

One typing engine, two focus policies: desktop keeps the input focused, phones wait for a tap and let the keyboard close when you tap elsewhere.

Shivank Pandey

A desktop typing test wants the keyboard ready the moment the page loads. On a phone, focusing an input opens the on-screen keyboard, which covers half the screen before the reader has decided to type. Typestrix runs the same typing engine on both, and changes only the focus policy around it.

A real input under custom text

The passage is a set of character spans. Over it sits a real <input type="text"> with opacity-0 and inset-0, covering the whole text area. That input receives every key, opens the mobile keyboard, and fires change events; the spans and the separate caret only draw.

<input
    className="absolute inset-0 cursor-default opacity-0"
    autoComplete="off"
    autoCorrect="off"
    autoCapitalize="off"
    spellCheck={false}
    inputMode="text"
/>

Autocomplete, autocorrect, auto-capitalisation and spellcheck are all off because each one changes the text being measured. Because the input covers the passage, "tap the text" and "tap the input" are the same gesture, and that tap is what lets the browser open the keyboard.

Two policies, one engine

isTouchPrimary() matches phones and tablets: no hover and a coarse pointer. A touchscreen laptop with a mouse or trackpad does not match, so it gets the desktop policy.

MomentDesktopTouch-primary
Page loadFocus input on the next frameNothing; show the tap cue
Click or tap on empty pageRefocus inputNothing; keyboard may close
Tap a button, link, tab, switchRefocus just after the press (the click still lands)Nothing; keyboard closes
Input loses focusRefocus on the next frameNothing
Hardware key pressed elsewhereRefocus inputRefocus input (tablet keyboards)
RestartAlways refocusRefocus only if the input was focused

On desktop, useInputFocus installs mousedown, touchstart, keydown and input blur listeners on the document and pulls focus back on every one, so you can click anywhere and keep typing. On touch it installs only the keydown listener. Without that split, tapping "Test Settings" would focus the input again and the keyboard would pop straight back up over the sheet.

The first-visit journey on a phone

Pick a step, or use the arrows, to walk through the diagram.

Step through it. Every keyboard change follows something the user did.

Load the phone UI only for phones

Below the sm breakpoint the mode bar collapses into a single "Test Settings" button. The sheet behind it is a next/dynamic import with ssr: false, and it is not even rendered until the first pointerdown on the button. Desktop users never download its code. The site settings panel, room settings and profile editor also load their mobile drawers with next/dynamic.

useMediaQuery subscribes to matchMedia with useSyncExternalStore and returns false from its server snapshot. The server never touches window, and the first client render agrees with the server HTML before switching to the real value.

Restart reads the keyboard state first

const refocus = !isTouchPrimary() || document.activeElement === inputRef.current;
requestAnimationFrame(() => {
    resetCaretPosition();
    if (inputRef.current) {
        if (refocus) inputRef.current.focus();
        inputRef.current.setSelectionRange(0, 0);
        inputRef.current.value = "";
    }
});

The decision is taken before the frame, while the old input is still focused (or not). A restart while typing keeps the keyboard; a restart from the results screen or the settings sheet does not reopen it.

Integrity rules versus mobile keyboards

Signed-in tests reject paste, drops, and any single change that adds more than one character. Mobile keyboards often commit a whole word or a suggestion in one event (composition), and those commits are rejected too. Autocorrect being off reduces how often that happens, but some keyboards ignore the attribute.

That policy fits English character-by-character tests. It is not a complete answer for input methods that legitimately insert several characters at once (Chinese, Japanese, Korean IMEs, swipe typing). A multi-character insert is not proof of cheating; it is just not supported by these tests.

Guest practice is more permissive: paste and composition checks are off, while drop and context-menu blocking stay on for everyone.

The engine never needed to know it was on a phone. Every difference lives at the edges, in when focus is taken and when it is left alone, and every keyboard change follows something the user actually did.

Keep reading