Overview
TheToolbar component provides a floating formatting toolbar that appears whenever the user selects text. It is self-managed – once rendered inside YooptaEditor, it automatically listens to selection events, positions itself near the selection, and hides when no text is selected.

Features
- ✅ Automatic display on selection events
- ✅ Floating UI positioning (follows selection)
- ✅ Compound components (
Root,Group,Button,Separator) - ✅ Works with any formatting actions or custom buttons
- ✅ Lightweight hook for open/close control
- ✅ Full keyboard and accessibility support
Basic Usage
API Reference
Components
Toolbar.Root
Root floating container. Should receive getRootProps() from useToolbar().
children: ReactNodeclassName?: stringstyle?: CSSProperties
Toolbar.Group
Wraps related buttons together.
children, className?
Toolbar.Button
Individual toolbar button.
onClick?: (event) => voidactive?: booleandisabled?: booleantitle?: stringclassName?: string- spreads native
<button>props
Toolbar.Separator
Visual separator between groups.
Hook: useToolbar()
Full hook with Floating UI, selection listeners, etc. Use only in the component that renders the toolbar.
| Property | Type | Description |
|---|---|---|
isOpen | boolean | Whether the toolbar should be rendered |
getRootProps | () => RootProps | Props for <Toolbar.Root> |
state | 'open' | 'closed' | Internal state |
reference | HTMLElement | null | Floating reference element |
Lightweight hook: useToolbarActions()
Expose lightweight control (open/close/toggle) if needed.
Examples
Rich Formatting Toolbar
Toolbar with Custom Actions
Styling
CSS Variables
Custom styles / Tailwind
Accessibility
- Toolbar stays close to selection for context
- Buttons use
<button type="button">for proper semantics - Use
title/aria-labelfor icons to describe actions
Best Practices
Wrap formatting logic in conditions
Wrap formatting logic in conditions
Avoid overloading toolbar with too many actions
Avoid overloading toolbar with too many actions
tsx // Prefer 4–8 buttons, use ActionMenuList for less frequently used options Use separators to group related actions
Use separators to group related actions