Tiptap extension that provides list item functionality for rich text editors
npx @tessl/cli install tessl/npm-tiptap--extension-list-item@3.4.0The @tiptap/extension-list-item package provides list item functionality for Tiptap rich text editors. It enables creation and management of list items (<li> elements) that work seamlessly with bullet lists and ordered lists.
npm install @tiptap/extension-list-itemimport { ListItem } from '@tiptap/extension-list-item';
import type { ListItemOptions } from '@tiptap/extension-list-item';Default import:
import ListItem from '@tiptap/extension-list-item';CommonJS:
const { ListItem } = require('@tiptap/extension-list-item');import { Editor } from '@tiptap/core';
import { ListItem } from '@tiptap/extension-list-item';
import { BulletList } from '@tiptap/extension-bullet-list';
import { OrderedList } from '@tiptap/extension-ordered-list';
const editor = new Editor({
extensions: [
ListItem,
BulletList,
OrderedList,
],
content: `
<ul>
<li>First item</li>
<li>Second item</li>
</ul>
`,
});The ListItem extension is built on Tiptap's Node architecture and provides:
listItem node type with proper parsing and renderingparagraph block*)Creates a Tiptap node extension that handles list item functionality.
import type { Node } from '@tiptap/core';
/**
* List item node extension for Tiptap editors
* Enables creation and management of <li> elements
*/
const ListItem: Node<ListItemOptions>;Options interface for configuring the ListItem extension.
interface ListItemOptions {
/**
* The HTML attributes for a list item node.
* @default {}
* @example { class: 'custom-list-item' }
*/
HTMLAttributes: Record<string, any>;
/**
* The node type for bulletList nodes
* @default 'bulletList'
* @example 'myCustomBulletList'
*/
bulletListTypeName: string;
/**
* The node type for orderedList nodes
* @default 'orderedList'
* @example 'myCustomOrderedList'
*/
orderedListTypeName: string;
}Usage Examples:
import { Editor } from '@tiptap/core';
import { ListItem } from '@tiptap/extension-list-item';
// Basic configuration
const editor = new Editor({
extensions: [
ListItem,
],
});
// Custom configuration
const editor = new Editor({
extensions: [
ListItem.configure({
HTMLAttributes: {
class: 'my-list-item',
},
bulletListTypeName: 'customBulletList',
orderedListTypeName: 'customOrderedList',
}),
],
});The ListItem node has the following built-in properties:
interface ListItemNode {
/** Node name identifier */
name: 'listItem';
/** Content expression - allows paragraph followed by zero or more blocks */
content: 'paragraph block*';
/** Defining property - this node defines its content structure */
defining: boolean;
/** Parse HTML configuration - recognizes <li> tags */
parseHTML(): Array<{ tag: string }>;
/** Render HTML configuration - outputs <li> elements */
renderHTML(options: { HTMLAttributes: Record<string, any> }): [string, Record<string, any>, number];
}Built-in keyboard shortcuts for list item management:
interface ListItemKeyboardShortcuts {
/** Split list item at cursor position */
'Enter': () => boolean;
/** Indent/nest list item */
'Tab': () => boolean;
/** Outdent/lift list item */
'Shift-Tab': () => boolean;
}Keyboard Shortcut Behaviors:
When ListItem is installed, it enables these commands on the editor:
// Split current list item
editor.commands.splitListItem('listItem');
// Indent current list item
editor.commands.sinkListItem('listItem');
// Outdent current list item
editor.commands.liftListItem('listItem');The ListItem extension handles common edge cases: