Skip to content

fix(ui): commit popover forms through submit, not a key handler - #3030

Open
YousefED wants to merge 9 commits into
mobile/test-infrafrom
mobile/link-popover
Open

fix(ui): commit popover forms through submit, not a key handler#3030
YousefED wants to merge 9 commits into
mobile/test-infrafrom
mobile/link-popover

Conversation

@YousefED

@YousefED YousefED commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Third layer of the stack, on #3029.

The bug

Creating a link on Android didn't work: the URL never became a link and focus jumped to the next editor. A mobile IME picks what its Enter key does — with a lone text field outside a form it picks "Next": advance focus, no key event at all. A popover listening for Enter has nothing to hear. Being inside a real <form> is what makes the IME offer a submitting action instead (verified on a physical device, with enterkeyhint ruled out as the cause) — and Form.Root was a <div>, so its onSubmit could never fire.

The fix

Form.Root renders a real <form>; submission runs off its submit event. Three consequences, each pinned by tests:

  • HTML only submits implicitly with a submit button or exactly one field — the two-field link edit form would still reach nothing. So every form declares its submit control explicitly: Form.Root requires submitButton: ReactElement | "none", with ScreenReaderOnlySubmit in @blocknote/react as the standard control (visually hidden — clipped, not display:none — so assistive technology keeps a labelled control; tabIndex={-1} so sighted keyboard users never land on an invisible tab stop; CSS and dictionary in one copy instead of per skin). The embed tab passes its real button as the submitButton — inside the form, one commit path for click/Enter/IME-action, one labelled action — which also forced FilePanel.Button to take an explicit type (the skins disagreed on the default, which is what had exiled the button from the form in the first place).
  • No composition guard is needed on this path — the IME consumes the confirming Enter (it reaches the page as keyCode 229, which triggers no default action), so implicit submission cannot fire mid-composition; the isComposing checks the old keydown handlers carried don't transfer to the submit path. The tests pin the native contract against the real popover: accepting a candidate does not submit, Enter afterwards does.
  • One submission path makes the five Enter key handlers redundant; removed. EmbedTab had no form at all and gains one; the AI prompt menu's handler and onSubmit disagreed on whether Enter picks the highlighted suggestion or submits the raw text, and now share one decision.

Also: TextInput loses its onSubmit prop — every skin forwarded it onto the <input>, where submit never fires, so it was dead since #652 (and plausibly why the gap went unnoticed).

Notes for review

  • Breaking, for release notes: Form.Root requires submitButton (replaces the earlier optional opt-out), FilePanel.Button requires type, and the new dictionary key generic.form_submit (the submit control's accessible name) makes hand-rolled dictionaries a compile error until added. The 23 non-English translations are machine-generated and unreviewed.
  • Coverage limit, stated where it lives: emulation proves submission works with no key event at all (mobile/linkSubmit.test.tsx) — exactly what the IME's submitting action does — but which action the IME itself offers is an OS decision no emulation can observe. That half is on the manual release checklist (testing skill); linkSubmit.test.tsx's header documents the boundary. A device suite automating it exists parked on mobile/emulator-layer (test(device): local emulator layer — real Chrome/Gboard as normal CI #3034).
  • Platform facts asserted rather than assumed, now in their own end-to-end/platform/ directory (raw createElement fixtures, nothing BlockNote — the README states the contract): implicit-submission rules and composition behaviour, per engine, on the desktop engines and the emulated-android instance alike. All fixes proven red-first (details in commit messages).

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 8b50ed1a-4f98-49d3-9743-96becef76949

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vercel

vercel Bot commented Aug 31, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
blocknote Error Error Sep 1, 2026 6:35pm UTC
blocknote-website Error Error Sep 1, 2026 6:35pm UTC

Request Review

@pkg-pr-new

pkg-pr-new Bot commented Aug 31, 2026

Copy link
Copy Markdown

Open in StackBlitz

@blocknote/ariakit

npm i https://pkg.pr.new/@blocknote/ariakit@3030

@blocknote/code-block

npm i https://pkg.pr.new/@blocknote/code-block@3030

@blocknote/core

npm i https://pkg.pr.new/@blocknote/core@3030

@blocknote/diagram-block

npm i https://pkg.pr.new/@blocknote/diagram-block@3030

@blocknote/mantine

npm i https://pkg.pr.new/@blocknote/mantine@3030

@blocknote/math-block

npm i https://pkg.pr.new/@blocknote/math-block@3030

@blocknote/react

npm i https://pkg.pr.new/@blocknote/react@3030

@blocknote/server-util

npm i https://pkg.pr.new/@blocknote/server-util@3030

@blocknote/shadcn

npm i https://pkg.pr.new/@blocknote/shadcn@3030

@blocknote/xl-ai

npm i https://pkg.pr.new/@blocknote/xl-ai@3030

@blocknote/xl-docx-exporter

npm i https://pkg.pr.new/@blocknote/xl-docx-exporter@3030

@blocknote/xl-email-exporter

npm i https://pkg.pr.new/@blocknote/xl-email-exporter@3030

@blocknote/xl-multi-column

npm i https://pkg.pr.new/@blocknote/xl-multi-column@3030

@blocknote/xl-odt-exporter

npm i https://pkg.pr.new/@blocknote/xl-odt-exporter@3030

@blocknote/xl-pdf-exporter

npm i https://pkg.pr.new/@blocknote/xl-pdf-exporter@3030

commit: 89a2620

@github-actions

github-actions Bot commented Aug 31, 2026

Copy link
Copy Markdown
PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://TypeCellOS.github.io/BlockNote/pr-preview/pr-3030/

Built to branch gh-pages at 2026-09-01 09:00 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@YousefED
YousefED force-pushed the mobile/link-popover branch from 56c82a9 to 2b6ff77 Compare August 31, 2026 17:36
@YousefED
YousefED force-pushed the mobile/link-popover branch from 2b6ff77 to d5df900 Compare August 31, 2026 17:42
@YousefED
YousefED force-pushed the mobile/link-popover branch from d5df900 to 9909733 Compare August 31, 2026 17:49
@YousefED
YousefED force-pushed the mobile/link-popover branch from 9909733 to 72fae20 Compare August 31, 2026 17:51
@YousefED
YousefED force-pushed the mobile/link-popover branch from 72fae20 to dff52d6 Compare August 31, 2026 17:59
@YousefED
YousefED force-pushed the mobile/link-popover branch from dff52d6 to 45b00f6 Compare August 31, 2026 18:20
Comment thread packages/core/src/editor/managers/StyleManager.ts Outdated
Comment thread packages/mantine/src/form/TextInput.tsx Outdated
// popovers into its own container — so it doubles as "this popover belongs
// to the mobile toolbar", which is what the two behaviours below actually
// depend on. Named here so the reason isn't hidden behind an unrelated prop.
const isMobileToolbarPopover = !!portalRoot;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add a TODO here indicating this should be cleaned up once we've settled on a good portalling solution (that's still pending slack discussions)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO added (worktree).

Comment thread packages/mantine/src/blocknoteStyles.css
Comment thread packages/react/src/components/FilePanel/DefaultTabs/EmbedTab.tsx Outdated
Comment thread packages/shadcn/src/form/Form.tsx
Comment thread packages/shadcn/src/form/Form.tsx Outdated
Comment thread tests/src/end-to-end/platform/compositionSubmit.test.tsx
Comment thread tests/src/end-to-end/platform/implicitSubmit.test.tsx
Comment thread tests/src/end-to-end/mobile/mobileToolbar.test.tsx
Comment thread packages/mantine/src/form/TextInput.tsx Outdated
Creating a link on Android didn't work: the popover's URL never became a
link and focus jumped to the next editor instead.

The cause is that a mobile IME picks the action its Enter key performs,
and with a lone text field it picks "Next" — advancing focus and
dispatching no key event at all. A popover that only listens for Enter
therefore has nothing to hear. Putting the fields in a real `<form>` is
what makes the IME offer a submitting action instead, confirmed on a
device; `Form.Root` was a `<div>`, so `onSubmit` could never fire.

`Form.Root` now renders a `<form>`, and submission runs off its `submit`
event. That has three consequences worth calling out:

- HTML only submits implicitly when a form has a submit button or exactly
  one field, so the link *edit* form — url plus title — would still reach
  nothing. `Form.Root` renders a submit button to cover any field count.
  It is visually hidden rather than absent so assistive technology still
  has a labelled control, and outside the tab order so sighted keyboard
  users never land on a control they can't see.
- The browser performs implicit submission for an Enter that arrives with
  `isComposing: true`, so accepting an IME candidate would submit the
  popover mid-word. `useFormSubmit` guards that centrally, replacing the
  per-callsite `isComposing` checks that had already drifted apart.
- With one submission path, the five Enter handlers are redundant and are
  removed. `EmbedTab` had no form at all and gains one; the AI prompt
  menu's handler and `onSubmit` disagreed about whether Enter picks the
  highlighted suggestion or submits the typed text, and now share one
  decision.

`TextInput` also loses its `onSubmit` prop: every skin forwarded it to
the `<input>`, and `submit` only fires on a form and bubbles upward, so
it could never have fired. `EditLinkMenuItems` passed it, which is
plausibly why the gap went unnoticed.
Review follow-ups:

- The embed panel ended up with two submit controls: its own Embed button
  plus the hidden one `Form.Root` adds, so a screen reader announced two
  separate actions for the one thing that panel does. `Form.Root` now takes
  `hasOwnSubmitButton` for callers that supply their own.
- The three `TextInput`s hand-rolled ref merging. `mergeRefs` already exists
  here, but returns a fresh callback per call — which detaches and reattaches
  the ref every render — so this adds `useMergeRefs` alongside it, memoized
  the way `react-merge-refs` does, and uses that.
- The mantine popover keyed two behaviours off `portalRoot` while its
  comments explained them in terms of mobile. Same condition, but named, so
  the reason isn't hidden behind an unrelated prop.
- `useFormSubmit` documents that it exists for `Form.Root` implementations
  rather than applications.
…'t fail

Second review round, checking whether the tests added in the first one can
actually fail. Two could not:

- The composition tests built a synthetic form replicating what `Form.Root`
  does, so deleting the guard from `useFormSubmit` left them all green — the
  shipped code had no coverage at all. A test now drives the real link
  popover through a CDP composition, and fails when the guard is removed.
  The synthetic ones stay as what they are: the platform fact that a browser
  submits for an Enter carrying `isComposing: true`.
- "the embed tab commits exactly once" asserted one image was present, which
  is true whether the update ran once or twice. Its replacement counted the
  form's submit events, but that cannot fail either: only mantine runs in
  this suite and its panel button already defaults to `type="button"`. The
  structural check — no button inside the form — is what actually guards
  both the double-commit and the duplicate-control problems, and it does
  fail when the button is moved inside, so that one is kept and the
  outcome-based tests are dropped rather than left as decoration.

Also renames `hasOwnSubmitButton` to `omitSubmitButton`: EmbedTab's button
sits outside the form, so the form has no submit button at all and relies on
single-field implicit submission. The old name asserted something untrue of
its only caller, and hid the constraint the flag carries.
…es IMEs

The guard answered the wrong category of problem. `isComposing` checks are
needed in *keydown* handlers, because an IME-consumed key still dispatches
to JS — that is what the five removed Enter handlers were. Native form
submission never sees that key: the IME consumes the confirming Enter (it
reaches the page as keyCode 229, which the browser runs no default action
for), so implicit submission cannot fire mid-composition. This is why no
plain form on the web carries composition handling.

The state the guard defended — composition open, unconsumed trusted Enter
delivered — is one only CDP emulation can fabricate: `imeSetComposition`
sets composition state with no IME in the loop to consume the key. No real
IME produces the sequence. Worse, the guard carried real risk in the other
direction: Gboard's action key commits the composition and submits in one
press, so if any IME delivers `submit` before `compositionend`, the guard
would swallow a legitimate submission — the original bug, reintroduced for
exactly the users it claimed to protect.

`Form.Root` goes back to plain `preventDefault` wiring, `useFormSubmit` is
deleted, and the composition tests now pin the *native* contract against
the real popover: accepting a candidate does not submit, Enter afterwards
does.
Form.Root's optional omitSubmitButton becomes a required
submitButton: ReactElement | "none" — the compiler now forces every
caller to decide the form's one submit affordance instead of a boolean
opt-out defaulting silently (ReactElement, not ReactNode, so the
"none" sentinel can't be satisfied by an arbitrary string).
@blocknote/react owns the default control (ScreenReaderOnlySubmit,
which reads the dictionary) and its clip CSS, in one copy; the three
skin Forms collapse to rendering whatever they're given.

The embed tab shows why: its visible button is now the form's
submitButton — inside the <form>, one commit path for click, Enter and
a mobile IME's action key, one labelled action for assistive
technology. That required FilePanel.Button to take an explicit
type ("button" | "submit"): the skins disagreed on the default
(shadcn hardcoded submit, Mantine defaults to button), which is exactly
what had forced the button outside the form before.

Layout-wise the <form> is a semantic wrapper only, never a box: every
skin renders it as class bn-form and one shared rule gives it
display: contents. Ariakit and shadcn rendered no wrapper element at
all before the real <form> arrived, so their flex+gap containers
(popover contents, the file panel's tab column) lay out fields as
direct children; mantine's containers are block, making contents a
no-op there — verified per skin against computed layout.

Breaking (release notes): Form.Root requires submitButton;
FilePanel.Button requires type. The pointer:coarse input sizing in the
same stylesheet region is from #2982.
implicitSubmit and compositionSubmit assert browser behavior against raw
createElement fixtures — nothing BlockNote in them — so they move out of
form/ into end-to-end/platform/ with a README stating the contract: these
are the per-engine platform facts Form.Root's design rests on, and a red
test here after a browser update points at the platform fact that moved,
not at BlockNote.
The portalRoot-implies-mobile inference in Popover gets a TODO pending
the portalling discussion. TextInput documents why its manual
preventScroll focus and Mantine's traps can never fight: no trap runs in
the form popovers at all (Popover's trapFocus defaults to false), and in
trap-active subtrees nearby (toolbar Tab-cycling, desktop menus) the
data-autofocus attribute makes a trap pick this same element.

@matthewlipski matthewlipski left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on Android and iOS - works very nicely! Though the PR description focuses on the enter handling/form submission fixes, the whole issue of the virtual keyboard handling on focus moving to the input is also fixed. What change in the code is actually responsible for this? Since I don't really see that mentioned in the description.

Comment thread packages/ariakit/src/input/TextInput.tsx Outdated
Comment thread packages/react/src/components/FilePanel/DefaultTabs/EmbedTab.tsx Outdated
Comment thread packages/react/src/editor/ComponentsContext.tsx
From review: the manual focus block was copy-pasted across the three
skins and had already drifted (mantine's copy had grown a comment and a
data-autofocus attribute the others lacked). The hook in @blocknote/react
now owns the ref, the focus({ preventScroll: true }) effect, and the
rationale — including how the official implementations compare (React's
autoFocus is a bare .focus() at commit, which is exactly the scroll-yank
this exists to avoid; Mantine defers via setTimeout; floating-ui via
microtask + rAF) and why no extra deferral is used here: nothing to wait
for, and added hops erode the user-gesture window in which iOS Safari
lets a programmatic focus open the keyboard (validated on real iOS).

data-autofocus is set per skin only where the UI library reads it:
Mantine's focus trap and Ariakit's dialog initial-focus both select it
(Ariakit's popovers run autoFocusOnShow by default, so the attribute
makes their pick explicit instead of positional); shadcn's Base UI has
no attribute convention — its mechanism is the initialFocus prop — so
that skin omits it.
- EmbedTab's submit callback renamed to handleSubmit (consistency with
  EditLinkMenuItems).
- The Form contract docs in ComponentsContext trimmed to the contract;
  the device-verified rationale lives in the PR and its tests.
- One focus principle across skins, now enforced rather than raced:
  BlockNote owns focus in its popovers (useAutoFocus). Ariakit's
  autoFocusOnShow is disabled — its default bare-focuses the first
  tabbable (no preventScroll, plus a Safari scrollIntoView), the exact
  scroll-yank useAutoFocus avoids, previously masked only by effect
  ordering. Mantine's popover trapFocus pinned to its (identical)
  default, dead ternary dropped. data-autofocus stays only where the
  library reads it AND focuses safely — Mantine's trap; Ariakit fails
  the second test, Base UI the first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants