Selection Toolbar
A floating toolbar that appears on text selection with formatting and utility actions.
Installation
pnpm dlx shadcn@latest add @diceui/selection-toolbarLayout
Import the parts, and compose them together.
import {
SelectionToolbar,
SelectionToolbarItem,
SelectionToolbarSeparator,
} from "@/components/ui/selection-toolbar";
return (
<SelectionToolbar>
<SelectionToolbarItem />
<SelectionToolbarSeparator />
</SelectionToolbar>
)Examples
Selection Info
Track selection information with the onSelectionChange callback to display word count, character count, and other metrics.
API Reference
SelectionToolbar
The root component that manages the toolbar's visibility and positioning.
Prop
Type
| Data Attribute | Value |
|---|---|
[data-state] | "open" | "closed" |
| CSS Variable | Description | Default |
|---|---|---|
--selection-toolbar-available-width | The available width in the viewport for the toolbar to fit within, accounting for collision boundaries. | Dynamic (e.g., 1200px) |
--selection-toolbar-available-height | The available height in the viewport for the toolbar to fit within, accounting for collision boundaries. | Dynamic (e.g., 800px) |
--selection-toolbar-anchor-width | The width of the selected text (anchor element). | Dynamic (e.g., 150px) |
--selection-toolbar-anchor-height | The height of the selected text (anchor element). | Dynamic (e.g., 24px) |
SelectionToolbarItem
An actionable item within the toolbar, typically containing an icon.
Prop
Type
SelectionToolbarSeparator
A visual separator between toolbar items.
Prop
Type
Accessibility
Keyboard Interactions
| Key | Description |
|---|---|
| Escape | Closes the toolbar and clears the text selection. |