Skip to content

Commit 13b551e

Browse files
committed
docs(react): document portalElements config
Adds a short "Configuring Portal Targets" section to the UI Components overview page and updates the example README to match the side-by-side demo.
1 parent a235126 commit 13b551e

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

  • docs/content/docs/react/components
  • examples/03-ui-components/20-portal-elements

docs/content/docs/react/components/index.mdx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,23 @@ BlockNote includes a number of UI Components (like menus and toolbars) that can
1414
{/* - [Image Toolbar](/docs/react/components/image-toolbar) */}
1515

1616
<CardTable path="/react/components" />
17+
18+
## Configuring Portal Targets
19+
20+
By default, all floating UI elements (toolbars, menus, table handles, etc.) portal into the editor's `bn-container` so they stay scoped to the editor. If your layout needs them to escape — e.g. an `overflow: hidden` ancestor that would clip large dropdowns, or a host modal with its own stacking context — pass a `portalElements` prop to `BlockNoteView`:
21+
22+
```tsx
23+
<BlockNoteView
24+
editor={editor}
25+
portalElements={{
26+
// Global default for any element not listed below.
27+
default: document.body,
28+
// Per-element overrides. Values can be HTMLElement, a CSS selector, or null (= document.body).
29+
tableHandles: ".bn-container",
30+
}}
31+
/>
32+
```
33+
34+
Keys mirror the default UI flags (`formattingToolbar`, `linkToolbar`, `slashMenu`, `emojiPicker`, `sideMenu`, `filePanel`, `tableHandles`, `comments`). Manually-mounted Controllers also accept a `portalElement` prop that takes precedence over the map. See the [Portal Targets example](/examples/ui-components/portal-elements).
35+
36+
Note: changing `portalElements.default` after mount requires remounting the editor (`editor.mount()` consults it once); per-element keys update reactively.

examples/03-ui-components/20-portal-elements/README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
# Configuring Portal Targets per Element
1+
# Configuring Portal Targets
22

3-
By default, BlockNote's floating UI elements (formatting toolbar, slash menu, table handles, etc.) mount inside the editor's `bn-container` element. The `portalElements` prop lets you change that — globally via `default`, or per element by key.
3+
By default, BlockNote's floating UI elements (formatting toolbar, slash menu, table handles, etc.) mount inside the editor's `bn-container`. The `portalElements` prop on `BlockNoteView` lets you change that — globally via `default`, or per element by key.
44

5-
In this example we deliberately wrap the editor in a small parent with `overflow: hidden` so the global default of `bn-container` would clip the slash menu and the formatting toolbar. We escape only those two to `document.body`, while keeping `tableHandles` inside `.bn-container` so the table handles can never escape the editor's visual boundary.
5+
This example renders two editors side-by-side, both wrapped in a small `overflow: hidden` container. The left editor uses the default — the slash menu is clipped by the editor's bounds. The right editor passes `portalElements={{ default: document.body }}` so floating UI escapes the wrapper and renders fully.
66

77
```tsx
88
<BlockNoteView
99
editor={editor}
10-
portalElements={{
11-
slashMenu: document.body,
12-
formattingToolbar: document.body,
13-
tableHandles: ".bn-container",
14-
}}
10+
portalElements={{ default: document.body }}
1511
/>
1612
```
1713

0 commit comments

Comments
 (0)