Skip to content
Sign upPro
Chat layoutsAsk popoverMenu

Ask popover (Pro)

ProIncluded in $99

Ask about any selection in an app: an Ask button at the selection, the answer streaming in a popover right there, and a way to keep it as a thread.

ProA handbook page: a sentence is selected, Ask opens a popover right there, and the answer streams in it.

Installation

$ pnpm dlx shadcn@latest add @chatcn-pro/ask-popover

Needs chatcn Pro

This command works with a Pro license, along with every Pro component.

Or start free: sign up and get three Pro components on us, with a new one every month.

Usage

tsx
import { AskPopover } from "@/components/ui/chatcn/pro/ask-popover"

<AskPopover
  messages={messages}
  status={status}
  onAsk={(question, quote) => ask(question, { quote })}
  onDismiss={resetConversation}
  onPromote={(quote) => openThread(quote, messages)}
>
  <Article />
</AskPopover>

Wrap any content. When the reader selects at least minLength characters inside it, a small Ask button appears at the end of the selection. It opens a popover anchored there: the quote on top, a question box, and the answer streaming in place, so the reader never leaves the page. The selection stays marked on every line it spans while the popover is open. The popover opens below the selection when there is room, otherwise above, and is never taller than the room it has. Once there is an answer, Continue in a thread hands the quote to onPromote. Start a fresh messages list for each quote, and clear it in onDismiss.

Examples

States

ProOpened on a selection, answered with Continue in a thread, and a failed answer.

Props

PropTypeNotes
childrenReactNodeThe content people select from
messagesChatcnMessage[]The thread, in the kit's message contract
status, error, onStop, onRetry"ready" | "submitted" | "streaming" | "error"Send becomes Stop while it streams; an error offers Try again
value, defaultValue, onValueChangestringThe draft, controlled or not
onAsk(question, quote) => voidA question about the quoted text
onDismiss() => voidThe popover closed
onPromote(quote) => voidContinue in a full thread. Hidden when not set
minLengthnumberShortest selection that offers Ask. Default 3
defaultQuotestringOpen on mount around [data-ask-anchor], with this quote
labelsPartial<AskPopoverLabels>Every string, for translation

Keyboard

KeyAction
TabThe Ask button follows the content in tab order while text is selected
Enter, Shift EnterAsk, new line
EscapeClose the popover

Accessibility

  • The popover is a dialog named by its quote, so a screen reader hears what is being asked about.
  • Opening moves focus to the question box.
  • The marked selection is decorative; the quote is repeated in text at the top of the popover.
  • A click outside does not close it while an answer is still streaming.

Motion

The Ask button enters with a short rise; the popover opens from the edge nearest the selection in 200 ms. Under reduced motion both appear without movement.