Usage
The EditorToolbar component displays a toolbar of formatting buttons that automatically sync their active state with the editor content. It supports three layout modes using the @tiptap/vue-3/menus package:
fixed(always visible)bubble(appears on text selection)floating(appears on empty lines)
BubbleMenu and FloatingMenu extensions.Items
Use the items prop as an array of objects with the following properties:
label?: stringicon?: IconComponentcolor?: ButtonProps['color']activeColor?: ButtonProps['color']size?: ButtonProps['size']kind?: "mark" | "textAlign" | "heading" | "link" | "image" | "blockquote" | "bulletList" | "orderedList" | "codeBlock" | "horizontalRule" | "paragraph" | "undo" | "redo" | "clearFormatting" | "duplicate" | "delete" | "moveUp" | "moveDown" | "suggestion" | "mention" | "emoji"disabled?: booleanloading?: booleanactive?: booleantooltip?: TooltipPropsslot?: stringonClick?: (e: MouseEvent) => voiditems?: EditorToolbarItem[] | EditorToolbarItem[][]class?: any
You can pass any property from the Button component such as color, size, etc.
items prop to create separated groups of items.items array of objects with the same properties as the items prop to create a DropdownMenu.Layout
Use the layout prop to change how the toolbar is displayed. Defaults to fixed.
Options
When using bubble or floating layouts, use the options prop to customize the positioning behavior using Floating UI options.
<template>
<B24Editor v-slot="{ editor }">
<B24EditorToolbar
:editor="editor"
:items="items"
layout="bubble"
:options="{
placement: 'top',
offset: 8,
flip: { padding: 8 },
shift: { padding: 8 }
}"
/>
</B24Editor>
</template>
Should Show
When using bubble or floating layouts, use the should-show prop to control when the toolbar appears. This function receives context about the editor state and returns a boolean.
<template>
<B24Editor v-slot="{ editor }">
<B24EditorToolbar
:editor="editor"
:items="items"
layout="bubble"
:should-show="({ view, state }) => {
const { selection } = state
const { from, to } = selection
const text = state.doc.textBetween(from, to)
return view.hasFocus() && !selection.empty && text.length > 10
}"
/>
</B24Editor>
</template>
Examples
With image toolbar
Use the should-show prop to create context-specific toolbars that appear only for certain node types. This example shows a bubble toolbar with download and delete actions that only appears when an image is selected.
With link popover
This example demonstrates how to create a custom link popover using the slot property on toolbar items and the Popover component.
- Create a Vue component that wraps a Popover with link editing functionality:
- Use the custom component in the toolbar with a named slot:
API
Props
Slots
Theme
export default defineAppConfig({
b24ui: {
editorToolbar: {
slots: {
root: 'focus:outline-none',
base: 'flex items-stretch gap-1.5',
group: 'flex items-center gap-0.5',
separator: 'w-px self-stretch bg-(--ui-color-design-tinted-na-stroke)'
},
variants: {
layout: {
bubble: {
base: 'backdrop-blur-3xl bg-(--ui-color-bg-content-primary) border border-(--ui-color-divider-default) rounded-md p-1'
},
floating: {
base: 'backdrop-blur-3xl bg-(--ui-color-bg-content-primary) border border-(--ui-color-divider-default) rounded-md p-1'
},
fixed: {
base: ''
}
}
}
}
}
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import bitrix24UIPluginVite from '@bitrix24/b24ui-nuxt/vite'
export default defineConfig({
plugins: [
vue(),
bitrix24UIPluginVite({
b24ui: {
editorToolbar: {
slots: {
root: 'focus:outline-none',
base: 'flex items-stretch gap-1.5',
group: 'flex items-center gap-0.5',
separator: 'w-px self-stretch bg-(--ui-color-design-tinted-na-stroke)'
},
variants: {
layout: {
bubble: {
base: 'backdrop-blur-3xl bg-(--ui-color-bg-content-primary) border border-(--ui-color-divider-default) rounded-md p-1'
},
floating: {
base: 'backdrop-blur-3xl bg-(--ui-color-bg-content-primary) border border-(--ui-color-divider-default) rounded-md p-1'
},
fixed: {
base: ''
}
}
}
}
}
})
]
})