Dice UI

Selection Toolbar

A floating toolbar that appears on text selection with formatting and utility actions.

API

Installation

pnpm dlx shadcn@latest add @diceui/selection-toolbar

Layout

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 AttributeValue
[data-state]"open" | "closed"
CSS VariableDescriptionDefault
--selection-toolbar-available-widthThe available width in the viewport for the toolbar to fit within, accounting for collision boundaries.Dynamic (e.g., 1200px)
--selection-toolbar-available-heightThe available height in the viewport for the toolbar to fit within, accounting for collision boundaries.Dynamic (e.g., 800px)
--selection-toolbar-anchor-widthThe width of the selected text (anchor element).Dynamic (e.g., 150px)
--selection-toolbar-anchor-heightThe 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

KeyDescription
EscapeCloses the toolbar and clears the text selection.

On this page