Add a dropdown menu for list types
A dropdown menu for selecting from multiple list types.
Install
You can add the component via Tiptap CLI (for Vite or Next.js)
npx @tiptap/cli add list-dropdown-menu
Manual Integration
For frameworks other than Vite or Next.js, add the component manually from the open-source repository.
Import styles
This component requires you to import our styles which were added to styles/keyframe-animation.scss
and styles/_variables.scss
.
Usage
import { EditorContent, EditorContext, useEditor } from '@tiptap/react'
import { StarterKit } from '@tiptap/starter-kit'
import { TaskList } from '@tiptap/extension-task-list'
import { TaskItem } from '@tiptap/extension-task-item'
import { ListDropdownMenu } from '@/components/tiptap-ui/list-dropdown-menu'
import '@/components/tiptap-node/code-block-node/code-block-node.scss'
import '@/components/tiptap-node/list-node/list-node.scss'
import '@/components/tiptap-node/paragraph-node/paragraph-node.scss'
export default function MyEditor() {
const editor = useEditor({
immediatelyRender: false,
extensions: [StarterKit, TaskList, TaskItem.configure({ nested: true })],
content: `
<ul>
<li>
<strong>Bold</strong> for emphasis with <code>**</code> or <code>⌘+B</code> or the <code>B</code> button.
</li>
<li>
<em>Italic</em> for subtle nuances with <code>*</code> or <code>⌘+I</code> or the <code>I</code> button.
</li>
<li>
<s>Strikethrough</s> to show revisions with <code>~~</code> or the <code>~~S~~</code> button.
</li>
</ul>
<ul data-type="taskList">
<li data-type="taskItem" data-checked="true">
<div>
Test template
</div>
</li>
<li data-type="taskItem" data-checked="false">
<div>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://tiptap.dev/pricing">Create account</a>
</div>
</li>
<li data-type="taskItem" data-checked="false">
<div>
Download free template
</div>
</li>
</ul>
`,
})
return (
<EditorContext.Provider value={{ editor }}>
<div className="tiptap-button-group" data-orientation="horizontal">
<ListDropdownMenu types={['bulletList', 'orderedList', 'taskList']} />
</div>
<EditorContent editor={editor} role="presentation" />
</EditorContext.Provider>
)
}
Props
Name | Type | Default | Description |
---|---|---|---|
editor | Editor | null | null | The Tiptap editor instance |
types | Array<'bulletList' | 'orderedList' | 'taskList'> | ['bulletList', 'orderedList', 'taskList'] | The list types to include in the dropdown |
hideWhenUnavailable | boolean | false | Whether the menu is in a floating context |
onOpenChange | (isOpen: boolean) => void | - | Callback when dropdown open state changes |
Requirements
Used reference components
use-tiptap-editor
(hook)tiptap-utils
(lib)list-button
(ui)button
(primitive)dropdown-menu
(primitive)list-icon
(icon)chevron-down-icon
(icon)
Open source feature(s)
@tiptap/extension-task-list
@tiptap/extension-task-item