Selection actions
A React component in Beamline's AI & agents category.
Select a passage and hand it to the agent: a bar over the selection with quick actions, your own instruction and More; while the agent works it says so, and its suggestion comes back to Replace, Copy or Discard, with the passage kept marked.
Use it for
- Letting people select text in a document or an answer and ask the agent to rewrite, shorten, explain or translate it.
Not for
- Formatting text (rich-text-editor's own toolbar).
- Asking about the whole document (prompt-bar).
- Comments on a selection (comment-thread).
Anatomy
- region (your text; programmatically focusable to return focus)
- bar (toolbar, portalled at the popover layer, above the selection or below when there is no room)
- instruction field with send
- quick actions (icon + label; icons only under 560px)
- More (menu)
- working line (spinner, action, the passage)
- error line with Retry
- suggestion with Discard, Copy, Replace
- passage mark (CSS highlight while focus is in the bar)
States
- closed
- open (a passage of minLength or more is selected inside the region)
- working
- suggestion
- refused (error, Retry)
- read-only (no onReplace: Copy and Discard only)
- disabled
- stale completion ignored after selection changes
- failed request retry
Keyboard
- Alt+Enter, while a passage is selected, moves focus into the bar's field
- ← → (Home, End) move along the bar; mirrored in RTL
- Enter in the field sends the instruction
- Escape closes the bar and returns focus to where it was (or the region)
- Pressing outside the region and the bar closes it
Motion
The bar arrives with enter-scale on --motion-in; it follows the selection on scroll and resize without animating; nothing runs while closed.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
children (required) | ReactNode | — | The selectable text. |
actions / maxVisible | SelectionAction[] / number | — | { id, label, icon?, busyLabel? }; past maxVisible (3) they fold under More. DEFAULT_SELECTION_ACTIONS: Improve, Shorten, Explain, Fix grammar, Translate. |
onAction | (request: { action, instruction?, selection: { text, start, end } }) => void | Promise<string | void> | — | Resolve with text to offer a suggestion; throw to show why it failed. action is "ask" for an own instruction. |
onReplace | (selection, replacement) => void | — | Shows Replace; update your text (start/end are offsets in the region's text). |
placeholder / label / minLength / disabled | string / number / boolean | — | |
classNames | SelectionActionsClassNames | — | |
style / ref | CSSProperties / native Ref | — |
Built from
- button
- dropdown-menu
- copy-button
- spinner
Dependencies
lucide-react, radix-ui
Import
import { SelectionActions, DEFAULT_SELECTION_ACTIONS } from "@/components/selection-actions/selection-actions";
Get it
Selection actions is part of Beamline: 190 React components and screens your coding agent (Claude Code, Codex, Cursor or any MCP client) installs into your app through Beamline's MCP server, as a ready-built package or as plain React source you can change. $49 one payment (regular $200), no subscription, a year of updates, one licence for your whole team. Get Beamline · Connect your agent
More in AI & agents
- Approval card: The agent stops and asks before it acts: what it wants to do, exactly what that changes, any choices it needs, and Approve or Reject; both run your…
- Attachment: A file tile: preview or typed glyph with the type named, name, size, upload progress, error with retry, and a keyboard-reachable remove.
- Chat thread: People talking to people: messages grouped by person and day, reactions, delivery and read receipts that glide to the newest message read, who is typing…
- Citations: Inline numbered citations that preview their source on hover or focus, plus a numbered source list; streamed answers flow in at an even pace with the…
- Context cards: The knowledge an agent retrieved before it answered: one card per chunk with what it is about, the text it read with the search words marked, how…
- Conversation: The scrolling column of a conversation: follows new content while you are at the bottom, stops when you scroll up to read, and offers a way back; shared…
- Flowchart: A workflow as steps on a dotted canvas: a trigger, conditions that branch into paths side by side, actions and waits, read top to bottom; during a run…
- Image generation: The frame an AI image is generated into: a field of brand-hued pixels breathes with the progress while the model works, then the image arrives —…
- Message: One turn in a conversation with an agent: the person's words in a quiet bubble, the agent's answer on the page with its orb mark, trace, tool calls and…
- Plan: An agent's plan: numbered steps with live status, progress, and Approve / Edit / Reject when it needs sign-off; approving shows progress, and a refusal…
- Prompt bar: The agent composer: a field that grows, @ to add a source, / for a command, a model picker, files and dictation, and one button that sends with progress…
- Reasoning: The agent's trace, fed by your stream: a shimmering label and the seconds so far while it works, then "Thought for N seconds"; steps that check off…
- Recommendation card: One suggestion from the agent that the person may take or leave: what it suggests, why, the expected effect and how sure it is (a meter and a word…
- Response: An assistant's answer as streamed markdown in the system's reading type: bursty tokens flow in at an even pace, each new word fades in through a short…
- Task rows: Background work an agent is doing, one row per task: status as a glyph and a word, what it produced, how long it has run or took, a progress bar while…
- Tool call: One tool call in an agent's run: status, what it did and a short result on one quiet row that opens to the exact input and output; stops for permission…