# Slash Menu
## Example
```svelte
```
## Documentation
## Usage
`SlashMenu` adds a `/` command menu to the editor. Type `/` to open it, then search and select a block type.
```svelte
```
Default items include Paragraph, Heading 1–3, Blockquote, Code Block, Bullet List, and Ordered List. Image and Embed items appear automatically when those extensions are registered.
## Custom items
Pass `items` as an array or a function for dynamic/async items.
```svelte
{
editor.chain().focus().deleteRange(range).toggleHeading({ level: 1 }).run();
}
},
{
id: 'divider',
label: 'Divider',
description: 'Horizontal rule',
command: ({ editor, range }) => {
editor.chain().focus().deleteRange(range).setHorizontalRule().run();
}
}
]}
/>
```
## Async items
Pass a function to load items dynamically. The function receives the search query.
```svelte
{
const items = getSlashMenuItems($editor);
return items.filter((item) => item.label.toLowerCase().includes(query.toLowerCase()));
}}
/>
```
## Custom item rendering
Use the `item` snippet to customize how each menu item looks.
```svelte
{#snippet item({ item: menuItem, isActive, select })}
{/snippet}
```
## Helper functions
```ts
import { getSlashMenuItems, getBlockTypeItems, getImageItem } from '@foxui/text';
// All available items for the editor
const items = getSlashMenuItems(editor);
// Block type items only (no image/embed)
const blockItems = getBlockTypeItems(editor);
// Image item (or undefined if ImageExtension not registered)
const imageItem = getImageItem(editor);
```
## API Reference
### SlashMenu
A "/" command menu for the editor. Type "/" to open, then search and select block types or actions. Registers as a ProseMirror plugin.
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| editor | `Editor` | `-` | The tiptap editor instance. (required) |
| items | `SlashMenuItem[] | ((query: string) => SlashMenuItem[] | Promise)` | `-` | Menu items as a static array or async function. Defaults to all available block types. |
| char | `string` | `'/'` | Trigger character for the menu. |
| pluginKey | `string` | `'slashMenu'` | Unique key for the suggestion plugin. |
| item | `Snippet<[{ item: SlashMenuItem; isActive: boolean; select: () => void }]>` | `-` | Snippet for custom rendering of each menu item. |
| class | `string` | `-` | CSS classes for the popup container. |
### SlashMenuItem
The data shape for slash menu items.
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| id | `string` | `-` | Unique identifier for the item. (required) |
| label | `string` | `-` | Display label. (required) |
| description | `string` | `-` | Optional description shown below the label. |
| icon | `string` | `-` | Optional icon identifier. |
| command | `(props: { editor: Editor; range: Range }) => void` | `-` | Function called when the item is selected. (required) |
### getSlashMenuItems
Returns default slash menu items filtered to only those with registered extensions. Includes block types, image, and embed.
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| editor | `Editor` | `-` | The tiptap editor instance. (required) |
### getBlockTypeItems
Returns block type items only (no image/embed). Useful for block type selectors.
| Prop | Type | Default | Description |
|------|------|---------|-------------|
| editor | `Editor` | `-` | The tiptap editor instance. (required) |