Skip to content

Commit e627112

Browse files
authored
refactor: portal floating UI elements to document.body to prevent overflow clipping BLO-1115 (#2591)
Floating UI elements (menus, toolbars, emoji picker) are now portaled to a dedicated container at document.body, preventing them from being clipped by overflow:hidden ancestors.
1 parent 6814026 commit e627112

File tree

27 files changed

+215
-133
lines changed

27 files changed

+215
-133
lines changed

docs/content/docs/react/styling-theming/overriding-css.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ BlockNote uses classes with the `bn-` prefix to style editor elements. Here are
2121

2222
#### Editor Structure
2323

24-
- `.bn-container`: Container for editor and all menus/toolbars.
25-
- `.bn-editor`: Main editor element.
24+
- `.bn-root`: Container class both the floating menus / toolbars and the editor
25+
- `.bn-container`: Container around `.bn-editor`
26+
- `.bn-editor`: Main editor element (the "contenteditable").
2627
- `.bn-block`: Individual block element (including nested).
2728
- `.bn-block-group`: Container for nested blocks.
2829
- `.bn-block-content`: Block content wrapper.

docs/content/docs/react/styling-theming/themes.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Here are each of the theme CSS variables you can set, with values from the defau
6767
--bn-border-radius: 6px;
6868
```
6969

70-
Setting these variables on the `.bn-container[data-color-scheme]` selector will overwrite them for both default light & dark themes. To overwrite variables separately for light & dark themes, use the `.bn-container[data-color-scheme="light"]` and `.bn-container[data-color-scheme="dark"]` selectors.
70+
Setting these variables on the `.bn-root[data-color-scheme]` selector will overwrite them for both default light & dark themes. To overwrite variables separately for light & dark themes, use the `.bn-root[data-color-scheme="light"]` and `.bn-root[data-color-scheme="dark"]` selectors.
7171

7272
## Programmatic Configuration
7373

examples/01-basic/12-multi-editor/src/App.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@ import "@blocknote/mantine/style.css";
55
import { useCreateBlockNote } from "@blocknote/react";
66

77
// Component that creates & renders a BlockNote editor.
8-
function Editor(props: { initialContent?: PartialBlock[] }) {
8+
function Editor(props: {
9+
initialContent?: PartialBlock[];
10+
theme: "dark" | "light";
11+
}) {
912
// Creates a new editor instance.
1013
const editor = useCreateBlockNote({
1114
initialContent: props.initialContent,
1215
});
1316

1417
// Renders the editor instance using a React component.
15-
return <BlockNoteView editor={editor} style={{ flex: 1 }} />;
18+
return (
19+
<BlockNoteView theme={props.theme} editor={editor} style={{ flex: 1 }} />
20+
);
1621
}
1722

1823
export default function App() {
1924
// Creates & renders two editors side by side.
2025
return (
2126
<div style={{ display: "flex" }}>
2227
<Editor
28+
theme="dark"
2329
initialContent={[
2430
{
2531
type: "paragraph",
@@ -35,6 +41,7 @@ export default function App() {
3541
]}
3642
/>
3743
<Editor
44+
theme="light"
3845
initialContent={[
3946
{
4047
type: "paragraph",

examples/02-backend/04-rendering-static-documents/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export default function App() {
5757
// additional class names/attributes depend on the UI library you're using,
5858
// whether you want to show light or dark more, etc. It's easiest to just
5959
// check the rendered editor HTML to see what you need to add.
60-
<div className="bn-container bn-mantine">
60+
<div className="bn-root bn-container bn-mantine">
6161
<div
6262
className="ProseMirror bn-editor bn-default-styles"
6363
dangerouslySetInnerHTML={{ __html: html }}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
.bn-container[data-changing-font-demo] .bn-editor * {
1+
.bn-root[data-changing-font-demo] .bn-editor * {
22
font-family: "Comic Sans MS", sans-serif;
33
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
/* Adds border and shadow to editor */
2-
.bn-container[data-theming-css-demo] .bn-editor * {
2+
.bn-root[data-theming-css-demo] .bn-editor * {
33
color: blue;
44
}
55

66
/* Makes slash menu hovered items blue */
7-
.bn-container[data-theming-css-demo]
8-
.bn-suggestion-menu-item[aria-selected="true"],
9-
.bn-container[data-theming-css-demo] .bn-suggestion-menu-item:hover {
7+
.bn-root[data-theming-css-demo] .bn-suggestion-menu-item[aria-selected="true"],
8+
.bn-root[data-theming-css-demo] .bn-suggestion-menu-item:hover {
109
background-color: blue;
1110
}

examples/04-theming/04-theming-css-variables/src/styles.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Base theme */
2-
.bn-container[data-theming-css-variables-demo][data-color-scheme] {
2+
.bn-root[data-theming-css-variables-demo][data-color-scheme] {
33
--bn-colors-editor-text: #222222;
44
--bn-colors-editor-background: #ffeeee;
55
--bn-colors-menu-text: #ffffff;
@@ -21,7 +21,7 @@
2121
}
2222

2323
/* Changes for dark mode */
24-
.bn-container[data-theming-css-variables-demo][data-color-scheme="dark"] {
24+
.bn-root[data-theming-css-variables-demo][data-color-scheme="dark"] {
2525
--bn-colors-editor-text: #ffffff;
2626
--bn-colors-editor-background: #9b0000;
2727
--bn-colors-side-menu: #ffffff;

examples/05-interoperability/09-blocks-to-html-static-render/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ export default function App() {
191191
etc. It's easiest to just copy the class names and HTML attributes
192192
from an actual BlockNote editor. */}
193193
<div
194-
className="bn-container bn-mantine"
194+
className="bn-root bn-container bn-mantine"
195195
data-color-scheme={theme}
196196
data-mantine-color-scheme={theme}
197197
>

examples/05-interoperability/10-static-html-render/src/App.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import "@blocknote/core/fonts/inter.css";
22
import "@blocknote/mantine/style.css";
33
import { useCreateBlockNote, usePrefersColorScheme } from "@blocknote/react";
4-
import { useRef, useEffect } from "react";
54

65
export default function App() {
76
// Creates a new editor instance.
@@ -158,7 +157,7 @@ export default function App() {
158157
// Renders the exported static HTML from the editor.
159158
return (
160159
<div
161-
className="bn-container bn-mantine"
160+
className="bn-root bn-container bn-mantine"
162161
data-color-scheme={theme}
163162
data-mantine-color-scheme={theme}
164163
>

packages/ariakit/src/comments/Comment.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export const Comment = forwardRef<
5858
actions,
5959
children,
6060
edited,
61-
emojiPickerOpen, // Unused
61+
emojiPickerOpen,
6262
...rest
6363
} = props;
6464

@@ -72,7 +72,8 @@ export const Comment = forwardRef<
7272
(showActions === true ||
7373
showActions === undefined ||
7474
(showActions === "hover" && hovered) ||
75-
focused);
75+
focused ||
76+
emojiPickerOpen);
7677

7778
return (
7879
<AriakitGroup

0 commit comments

Comments
 (0)