Vanilla Breeze

selection-menu

Floating toolbar that appears on text selection. Composes action components for highlighting, sharing, notes, and comments.

Overview

The <selection-menu> component provides a Medium-style floating toolbar that appears when text is selected. It composes action components as children: <highlight-wc> for color highlighting, <share-wc> for sharing quotes, <note-wc> for private notes, and <comment-wc> for collaborative comments.

The element itself IS the toolbar — no DOM reparenting. It starts hidden and positions itself above the selection using fixed positioning with viewport clamping.

Attributes

AttributeTypeDefaultDescription
forstringID of a single target element to watch for text selection
idstringWhen set, elements with data-selection-menu="id" become targets

Demo

Select any text in the article below to see the toolbar.

Single Target

Many-to-One (Decoupled)

Define the menu once and let multiple elements reference it by ID via data-selection-menu.

JavaScript API

Events

EventDetailDescription
selection-menu:select{ range, text, target }Text selected, toolbar shown
selection-menu:dismissToolbar hidden

Accessibility

  • Toolbar uses role="toolbar"
  • Escape dismisses the toolbar
  • Clicking outside the toolbar dismisses it
  • Each child action has its own aria-label

Related