Skip to content

Slash menu

A slash menu is a popup of editor commands triggered by typing /. It filters the list as the user types and lets them pick with arrow keys or the mouse.

'use client'

import 'prosekit/basic/style.css'
import 'prosekit/basic/typography.css'

import { createEditor } from 'prosekit/core'
import { ProseKit } from 'prosekit/react'
import { useMemo } from 'react'

import { SlashMenu } from '../../ui/slash-menu'

import { defineExtension } from './extension'

export default function Editor() {
  const editor = useMemo(() => {
    const extension = defineExtension()
    return createEditor({ extension })
  }, [])

  return (
    <ProseKit editor={editor}>
      <div className="box-border h-full w-full min-h-36 overflow-y-hidden overflow-x-hidden rounded-md border border-solid border-gray-200 dark:border-gray-700 shadow-sm flex flex-col bg-[canvas] text-black dark:text-white">
        <div className="relative w-full flex-1 box-border overflow-y-auto">
          <div ref={editor.mount} className="ProseMirror box-border min-h-full px-[max(4rem,calc(50%-20rem))] py-8 outline-hidden outline-0 [&_span[data-mention=user]]:text-blue-500 [&_span[data-mention=tag]]:text-violet-500"></div>
          <SlashMenu />
        </div>
      </div>
    </ProseKit>
  )
}
npx shadcn@latest add @prosekit/react-ui-slash-menu

The slash menu is built on the autocomplete primitive, which detects the trigger character (/), tracks the query text after it, anchors the floating list to the cursor, and handles arrow-key navigation, Enter, and Escape.

AutocompleteRoot                 # root component
└── AutocompletePositioner       # anchors the popup to the cursor
    └── AutocompletePopup        # the floating panel
        ├── AutocompleteItem     # one per command (heading, list, table, …)
        └── AutocompleteEmpty    # shown when no item matches the query

Each AutocompleteItem's onSelect runs an editor command. The regex you pass to AutocompleteRoot decides what counts as the trigger.

  • Mention menu: same primitive, with @ or # as the trigger character.