You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/docs/react/components/suggestion-menus.mdx
+64Lines changed: 64 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,6 +58,70 @@ Passing `slashMenu={false}` to `BlockNoteView` tells BlockNote not to show the d
58
58
59
59
`getItems` should return the items that need to be shown in the Slash Menu, based on a `query` entered by the user (anything the user types after the `triggerCharacter`). In this case, we simply append the "Hello World" item to the default Slash Menu items, and use `filterSuggestionItems` to filter the full list of items based on the user query.
60
60
61
+
### Item Grouping & Ordering
62
+
63
+
Slash Menu items are rendered in the same order as the items returned from `getItems`. Adjacent items which share the same `group` attribute are rendered together in the same group under a single label.
64
+
65
+
#### Ordering
66
+
67
+
Items appear in the menu in the exact order of the array. Reordering the array reorders the menu:
68
+
69
+
```typescript
70
+
getItems={async (query) =>
71
+
filterSuggestionItems(
72
+
[
73
+
insertHelloWorldItem(editor), // Shown first
74
+
...getDefaultReactSlashMenuItems(editor), // Shown after
75
+
],
76
+
query,
77
+
)
78
+
}
79
+
```
80
+
81
+
#### Grouping
82
+
83
+
Items with the same `group` attribute must be **adjacent** in the array to be rendered as one group. If items with the same `group` are separated by items with a different `group`, they will be rendered as two separate groups, each with their own label:
84
+
85
+
```typescript
86
+
// Renders as a single "Basic" group:
87
+
[
88
+
{ title: "Item A", group: "Basic", /* ... */ },
89
+
{ title: "Item B", group: "Basic", /* ... */ },
90
+
{ title: "Item C", group: "Other", /* ... */ },
91
+
]
92
+
93
+
// Renders as two separate "Basic" groups, with "Other" between them:
In this example, we filter and reorder the default Slash Menu items so that only the "Basic blocks" and "Headings" groups are shown, with "Basic blocks" appearing first.
4
+
5
+
**Try it out:** Press the "/" key to open the Slash Menu and see the reordered groups!
Copy file name to clipboardExpand all lines: playground/src/examples.gen.tsx
+23Lines changed: 23 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -851,6 +851,29 @@
851
851
"slug": "ui-components"
852
852
},
853
853
"readme": "This example demonstrates how to use the `DRAG_EXCLUSION_CLASSNAME` to create separate drag & drop areas that don't interfere with BlockNote's built-in block drag & drop functionality.\n\n## Features\n\n- **Drag Exclusion**: Elements with the `bn-drag-exclude` classname are treated as separate drag & drop operations\n- **Independent Drag Areas**: Create custom drag & drop functionality alongside BlockNote's editor\n- **No Interference**: Custom drag operations won't trigger BlockNote's block reordering\n- **Side-by-side Demo**: Shows the editor and custom drag area working independently\n\n## How It Works\n\nBy adding the `DRAG_EXCLUSION_CLASSNAME` (`bn-drag-exclude`) to an element, you tell BlockNote's drag & drop handlers to ignore all drag events within that element and its children. This allows you to implement your own custom drag & drop logic without conflicts.\n\nThe exclusion check works by traversing up the DOM tree from the drag event target, checking if any ancestor has the exclusion classname. If found, BlockNote's handlers return early, leaving your custom handlers in full control.\n\n## Code Highlights\n\n### Import the constant:\n\n```tsx\nimport { DRAG_EXCLUSION_CLASSNAME } from \"@blocknote/core\";\n```\n\n### Apply it to your custom drag area:\n\n```tsx\n<div className={\"drag-demo-section \" + DRAG_EXCLUSION_CLASSNAME}>\n {/* Your custom drag & drop UI */}\n <div draggable onDragStart={handleDragStart} onDrop={handleDrop}>\n Custom draggable items\n </div>\n</div>\n```\n\n## Use Cases\n\n- **Custom UI elements**: Add draggable components within or near the editor\n- **File upload areas**: Create drag-and-drop file upload zones\n- **Sortable lists**: Implement custom sortable lists alongside the editor\n- **External integrations**: Integrate with third-party drag & drop libraries\n\n**Relevant Docs:**\n\n- [Side Menu (Drag Handle)](/docs/react/components/side-menu)\n- [Editor Setup](/docs/getting-started/editor-setup)"
"readme": "In this example, we filter and reorder the default Slash Menu items so that only the \"Basic blocks\" and \"Headings\" groups are shown, with \"Basic blocks\" appearing first.\n\n**Try it out:** Press the \"/\" key to open the Slash Menu and see the reordered groups!\n\n**Relevant Docs:**\n\n- [Item Grouping & Ordering](/docs/react/components/suggestion-menus)\n- [Changing Slash Menu Items](/docs/react/components/suggestion-menus)\n- [Editor Setup](/docs/getting-started/editor-setup)"
0 commit comments