Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
03e86dd
Added demo
matthewlipski Aug 3, 2026
e45f5a1
Replaced demo toolbar with actual toolbar
matthewlipski Aug 6, 2026
d9902bf
Properly fixed dropdowns
matthewlipski Aug 7, 2026
af12646
- Fixed link button popover close dismissing virtual keyboard
matthewlipski Aug 7, 2026
1d4fbe3
Added transition to toolbar
matthewlipski Aug 12, 2026
07d9ff7
Replaced hook with pure CSS
matthewlipski Aug 13, 2026
faa72b5
Added docs
matthewlipski Aug 13, 2026
d070f14
Removed redundant `direction` prop
matthewlipski Aug 13, 2026
ece1f83
Merged main
matthewlipski Aug 13, 2026
e23b2f3
Refactored `useVirtualViewportRect`
matthewlipski Aug 14, 2026
57b68bf
Fixed some SSR issues
matthewlipski Aug 17, 2026
dfb89ac
Removed `portalRoot` prop
matthewlipski Aug 17, 2026
5a5fcd1
Merge branch 'main' into mobile-toolbar-demo
matthewlipski Aug 17, 2026
4b920a1
Implemented PR feedback
matthewlipski Aug 17, 2026
52933c2
Removed unused component
matthewlipski Aug 17, 2026
8a03207
Small fix
matthewlipski Aug 17, 2026
f779a4b
Increased mobile formatting toolbar tap target size
matthewlipski Aug 17, 2026
19428d4
- Fixed `getActiveStyles` with empty selections
matthewlipski Aug 20, 2026
a174fef
Refactored `FormattingToolbarController` to handle whether the deskto…
matthewlipski Aug 20, 2026
51aa828
Made mobile toolbar only appear when attached editor instance is focused
matthewlipski Aug 20, 2026
9c748cc
Fixed toolbar select desktop regression
matthewlipski Aug 20, 2026
3a95797
Increased required threshold to detect orientation change
matthewlipski Aug 20, 2026
69c6a71
Fixed formatting toolbar not opening when using touch-capable device …
matthewlipski Aug 20, 2026
a42e93c
Made mobile formatting toolbar center-aligned
matthewlipski Aug 20, 2026
1d0ef95
Small fix
matthewlipski Aug 20, 2026
e441113
docs: name the mobile toolbar layouts + add layout toggle to the exam…
YousefED Aug 20, 2026
09692f4
Merge remote-tracking branch 'origin/mobile-toolbar-demo' into mobile…
matthewlipski Aug 20, 2026
d4079d4
Made `.bn-scroll-host` class name apply all necessary styles automati…
matthewlipski Aug 20, 2026
b05f7ab
Added second editor to example
matthewlipski Aug 20, 2026
cef137d
Cached `isTouchDevice` result
matthewlipski Aug 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions docs/content/docs/react/components/formatting-toolbar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,60 @@ The first element in the default Formatting Toolbar is the Block Type Select, an
<Example name="ui-components/formatting-toolbar-block-type-items" />

Here, we use the `FormattingToolbar` component but keep the default buttons (we don't pass any children). Instead, we pass our customized Block Type Select items using the `blockTypeSelectItems` prop.

## Mobile Formatting Toolbar

On touch devices, BlockNote's default UI replaces the floating Formatting Toolbar with a mobile Formatting Toolbar that sits just above the on-screen keyboard. It shows the same items as the regular Formatting Toolbar and is enabled by default - there's nothing to set up. Open any of the examples above on a phone to see it.

The mobile Formatting Toolbar works with two page layouts. Which one you get is decided purely by your app's CSS:

- **Scrolling document** (the default): the page scrolls as usual and BlockNote repositions the toolbar as you scroll.
- **Scroll container**: the document itself doesn't scroll; a container pinned to the visual viewport scrolls instead, and the toolbar never has to move.

### Scrolling document

This is what you get without any changes to your app. The toolbar follows the visible area above the keyboard as the page scrolls. Mobile browsers only report visual viewport changes after the fact, so the toolbar can lag or jitter slightly while the page is scrolling. If that matters for your app, switch to a scroll container.

### Scroll container

In this layout, `<html>` and `<body>` are locked and all page content lives inside a single scroll container that BlockNote keeps aligned with the visual viewport. Since the document never scrolls, the toolbar can stay at a truly fixed position and the lag/jitter disappears. Since the document no longer scrolls, this comes with some potential trade-offs. Browser gestures that rely on document scrolling, like pull-to-refresh, may stop working and browser UI elements like the address bar, which normally hides and reappears as you scroll, may stay fixed. Note that these trade-offs are browser-dependent - some will have neither, while others will have both.

To set this up, add the `bn-scroll-host` class to your scroll container:

```tsx
<div className="bn-scroll-host">{/* nav, editor, page content... */}</div>
```

<Callout type="warning">
Your app should only ever have a single `bn-scroll-host` element. It's pinned
to the visual viewport with `position: fixed`, so multiple hosts would overlap
each other. Wrap all your scrollable page content in one host.
</Callout>

That's all the setup needed. BlockNote injects the following styles for you:

```css
html:has(.bn-scroll-host),
body:has(.bn-scroll-host) {
overflow: hidden;
}
```

This locks scrolling on `<html>` and `<body>` whenever a `bn-scroll-host` element is present. It's then pinned to the visual viewport using the `--bn-vv-*` CSS variables that BlockNote publishes on `<html>`:

```css
.bn-scroll-host {
position: fixed;
top: var(--bn-vv-top, 0px);
left: var(--bn-vv-left, 0px);
width: var(--bn-vv-width, 100vw);
height: var(--bn-vv-height, 100dvh);
overflow-y: auto;
-webkit-overflow-scrolling: touch;
overscroll-behavior: contain;
}
```

These variables track the [visual viewport](https://developer.mozilla.org/en-US/docs/Web/API/VisualViewport) - the part of the page actually visible above the keyboard. BlockNote keeps `--bn-vv-top`, `--bn-vv-left`, `--bn-vv-width`, and `--bn-vv-height` (plus `--bn-vv-scale`, the pinch-zoom factor) up to date as the keyboard opens and closes and as the user pans or zooms, so the scroll container always lines up with the visible area above the keyboard without any JavaScript on your end.

Because this layout changes how the whole page scrolls, the example can't be embedded here - open the [standalone example](https://playground.blocknotejs.org/ui-components/mobile-formatting-toolbar?hideMenu=true) on a phone instead. It puts a navigation bar, some static text, and the editor inside a container with the `bn-scroll-host` class, and the switch in the navigation bar toggles the pinned scroll container layout on and off so you can compare it with the default scrolling document. Select some text and scroll in each layout to see the difference.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"playground": true,
"docs": true,
"docs": false,
"author": "areknawo",
"tags": [
"Intermediate",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Mobile Formatting Toolbar

This example demos the opt-in **scroll container** layout: adding the `bn-scroll-host` class to your scroll container locks `html`/`body` scrolling and pins the container to the visual viewport (BlockNote injects the styles), so the toolbar stays perfectly in place while scrolling and zooming. Use the switch in the nav bar to toggle it off and compare it with the default scrolling document layout.

**Relevant Docs:**

- [Mobile Formatting Toolbar](/docs/react/components/formatting-toolbar#mobile-formatting-toolbar)
- [Editor Setup](/docs/getting-started/editor-setup)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Experimental Mobile Formatting Toolbar</title>
<title>Mobile Formatting Toolbar</title>
<script>
<!-- AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY -->
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@blocknote/example-ui-components-experimental-mobile-formatting-toolbar",
"name": "@blocknote/example-ui-components-mobile-formatting-toolbar",
"description": "AUTO-GENERATED FILE, DO NOT EDIT DIRECTLY",
"type": "module",
"private": true,
Expand Down
63 changes: 63 additions & 0 deletions examples/03-ui-components/14-mobile-formatting-toolbar/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import "@blocknote/core/fonts/inter.css";
import { useCreateBlockNote } from "@blocknote/react";
import { BlockNoteView } from "@blocknote/mantine";
import "@blocknote/mantine/style.css";
import { useState } from "react";

import "./style.css";
import { StaticText, NavBar } from "./DummyUI";

// Enough content that the editor actually overflows, so scrolling is testable.
const initialContent = [
{ type: "paragraph" as const, content: "Welcome to this demo!" },
{
type: "paragraph" as const,
content:
"Select some text to bring up the toolbar, then scroll. With the pinned " +
"scroll container layout on, it stays put because the document itself " +
"doesn't scroll. Toggle it off in the nav bar to compare.",
},
...Array.from({ length: 20 }, (_, i) => ({
type: "paragraph" as const,
content:
`Filler paragraph ${i + 1}. Select some text here and bring up the ` +
"keyboard to see the toolbar sit above it.",
})),
];

export default function App() {
const editor = useCreateBlockNote({ initialContent });
// A second editor, to check the mobile toolbar still works with multiple
// editors on a page: the scroll-host styles are injected only once and each
// editor tracks the shared visual viewport independently.
const secondEditor = useCreateBlockNote({ initialContent });

// Which element scrolls the page. The "pinned scroll container" layout is
// opt-in via a single class: adding `bn-scroll-host` to the scroll container
// makes BlockNote's injected styles lock document scroll and pin the container
// to the visual viewport. Switching layouts is therefore just adding/removing
// the class - a real app would apply it unconditionally, the switch is only
// here so you can compare both.
const [scrollMode, setScrollMode] = useState<
"scrolling-document" | "scroll-container"
>("scroll-container");

return (
<div
className={
scrollMode === "scroll-container" ? "bn-scroll-host" : undefined
}
>
<NavBar scrollMode={scrollMode} onScrollModeChange={setScrollMode} />
<main className="app-main">
<StaticText />
{/* On mobile, the default UI automatically shows the mobile formatting
toolbar above the keyboard - no extra setup needed. */}
<BlockNoteView editor={editor} />
<StaticText />
<BlockNoteView editor={secondEditor} />
<StaticText />
</main>
</div>
);
}
100 changes: 100 additions & 0 deletions examples/03-ui-components/14-mobile-formatting-toolbar/src/DummyUI.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { useState } from "react";

function HamburgerMenu() {
const [open, setOpen] = useState(false);

return (
<div className="dummy-hamburger">
<button
type="button"
className="dummy-hamburger-button"
aria-label="Menu"
aria-expanded={open}
onClick={() => setOpen((v) => !v)}
>
<span />
<span />
<span />
</button>
{open && (
<nav className="dummy-hamburger-menu">
<a href="#">Home</a>
Comment thread
matthewlipski marked this conversation as resolved.
<a href="#">Documents</a>
<a href="#">Shared with me</a>
<a href="#">Settings</a>
</nav>
)}
</div>
);
}

export function NavBar(props: {
scrollMode: "scrolling-document" | "scroll-container";
onScrollModeChange: (
scrollContainer: "scrolling-document" | "scroll-container",
) => void;
}) {
return (
<header className="dummy-top-nav">
<HamburgerMenu />
<span className="dummy-top-nav-title">Lorem Ipsum</span>
{/* Switches between the default "scrolling document" layout and the
"pinned scroll container" layout, to compare the toolbar in both. */}
<button
type="button"
className="dummy-layout-toggle"
aria-pressed={props.scrollMode === "scroll-container"}
onClick={() =>
props.onScrollModeChange(
props.scrollMode === "scroll-container"
? "scrolling-document"
: "scroll-container",
)
}
>
Pinned scroll container
<span className="dummy-layout-toggle-track" aria-hidden="true" />
</button>
</header>
);
}

/** A block of static page text, to sit around the editor. */
export function StaticText() {
return (
<section className="dummy-prose">
<h2>Lorem Ipsum</h2>
<p>
Elit ipsum qui deserunt deserunt. Qui labore eu esse veniam excepteur.
Aute ipsum qui dolore in ipsum commodo adipisicing velit. Qui
consectetur et cupidatat consectetur sunt anim excepteur reprehenderit
sunt quis magna aliqua laborum. Lorem irure est ipsum ea nisi incididunt
culpa qui consequat eiusmod deserunt ipsum nostrud velit laboris.
</p>
<p>
Culpa quis id ipsum enim proident dolore non. Ad occaecat nostrud
eiusmod pariatur occaecat nisi voluptate nulla. Nisi quis ut esse ex
reprehenderit Lorem tempor ex tempor id sit officia. Commodo sunt sint
aliqua quis reprehenderit. Occaecat id ad dolor officia qui sunt dolor.
Consectetur magna excepteur in minim pariatur qui elit in sit consequat
aliquip voluptate laboris. Reprehenderit et eu dolor ex cupidatat aliqua
in elit anim eiusmod et adipisicing. Cupidatat fugiat fugiat amet duis.
</p>
<p>
Voluptate quis dolor ipsum commodo fugiat sit tempor tempor non aliqua
qui. Veniam consectetur mollit consequat exercitation sit ad. Lorem amet
deserunt qui sint et. Sint aute cillum aliqua pariatur cillum id.
Consectetur proident Lorem qui laborum id in sit. Aute aute irure nisi
est veniam Lorem. Anim labore irure ut sit mollit velit et duis veniam
ipsum aliquip.
</p>
<p>
Occaecat dolore excepteur qui proident laborum. Dolor deserunt cillum
veniam nulla minim eu in est aute nulla anim incididunt ea. Anim aliquip
aute duis aliqua eu pariatur est dolor magna Lorem dolore do sunt
aliquip est. Laborum pariatur fugiat do reprehenderit tempor cupidatat
proident ipsum ad dolor laboris.
</p>
</section>
);
}
Loading
Loading