BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/moumenlab/caret-mention-popover

Caret-Anchored Mention Popover

moumenlab/caret-mention-popover
FreeComponent

An @-mention popover anchored to the text caret via a hidden mirror, gliding as you type.

Live preview

live · rendered by the registry
Rendered by moumenlab on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://lab.moumen.dev/r/caret-mention-popover.json

Source

registry/lab/caret-mention-popover/caret-mention-popover.tsxlab.moumen.dev/r/caret-mention-popover.json · first 6 KB
1"use client";
2
3import { useEffect, useId, useLayoutEffect, useRef, useState, type ReactNode } from "react";
4import { MotionConfig, motion } from "motion/react";
5
6// Mention composer - a caret-anchored @mention popover.
7//
8// A textarea won't tell you where its caret is - the only API is selectionStart,
9// a character index, no x/y. So most popovers anchor to the FIELD (bottom-left,
10// like a dropdown), which feels detached from what you're typing. This one
11// anchors to the CARET, with three stacked layers sharing one typography class
12// so their metrics can never drift:
13//
14// · input - the real textarea (transparent background, visible text).
15// · backdrop - behind it, same box, text painted TRANSPARENT; only the
16// highlight boxes show through (inserted mentions as pills, the live @query
17// as a lighter chip). The spans add zero advance (box-shadow fakes the
18// inset), so the backdrop's glyph grid matches the textarea exactly.
19// · mirror - invisible. value.slice(0, caret) is re-typeset into it plus a
20// marker <span>; the marker's offsetLeft/offsetTop IS the caret's x/y.
21//
22// The popover is positioned with `translate` (left/top stay 0), so following the
23// caret is one retargetable transition - it glides, and a fresh open snaps. It
24// clamps horizontally and flips above when the viewport runs out. Focus never
25// leaves the textarea: ↑↓/Enter/Tab drive the list via aria-activedescendant.
26//
27// Animation via motion/react (the pill fade + send-icon swap) plus CSS
28// transitions; honours prefers-reduced-motion. Requires the lab-theme tokens.
29// Fully Tailwind, no CSS files.
30
31const EASE = [0.22, 1, 0.36, 1] as const;
32const EASE_ICON = [0.2, 0, 0, 1] as const;
33
34// THE contract: input, backdrop and mirror all take this, so their metrics
35// (font, line height, wrap width, spacing) cannot drift apart.
36const TEXT = "font-[inherit] text-[0.9375rem] leading-6 tracking-normal whitespace-pre-wrap [overflow-wrap:break-word]";
37
38export interface Person {
39 name: string;
40 handle: string;
41}
42
43export interface MentionState {
44 open: boolean;
45 query: string;
46 matches: number;
47 caret: { x: number; y: number } | null;
48 placement: string;
49 anchor: string;
50 mentions: number;
51 lastMention: string | null;
52}
53
54interface Match {
55 person: Person;
56 score?: number;
57 nameRange: [number, number] | null;
58 handleRange: [number, number] | null;
59}
60
61// Word-prefix on the name beats handle-prefix beats substring.
62// … truncated

What it pulls in

npm packages

  • motion

Other registry items

  • https://lab.moumen.dev/r/lab-theme.json

Files it writes

  • registry/lab/caret-mention-popover/caret-mention-popover.tsx

Facts

Registry
moumenlab
Type
registry:component
Access
Free
Files written
1
Licence
MIT
In the index
at or before 2026-08-11
Last confirmed
today

Go to the source

Docs on moumenlab lab.moumen.dev moumen-soliman/lab on GitHub Raw registry item This item as JSON

More from moumenlab

All 14 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
Command Palette with Argument Chipscommand-palettemoumenlabComponentsFree1 dep
Drag-to-Reorder Listdrag-to-reorder-listmoumenlabComponentsFree1 dep
File Upload Staging Areafile-upload-stagingmoumenlabComponentsFree1 dep
Hover-Expand Icon Striphover-expand-icon-stripmoumenlabComponentsFree1 dep
Inertial Wheel Listinertial-wheel-listmoumenlabComponentsFree1 dep
Morphing Checkout Flowmorphing-checkoutmoumenlabComponentsFree1 dep
OTP Segmented Inputotp-segmented-inputmoumenlabComponentsFree1 dep
Schedule Builderschedule-buildermoumenlabComponentsFree1 dep

Also from Kynth Studios

Built for the same person as BlockDex

SkillWorks

Claude Code skills and plugins, scored

skillworks.kynth.studio

RuleStack

AGENTS.md gallery and agent-config comparison

rulestack.kynth.studio

ToolDrift

What the AI coding tools changed last night

tooldrift.kynth.studio

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex

The studio list

One product, taken apart, once a month

Kynth Studios pulls one shipped product open every month — what it does, what it cost to build, what the pipeline behind it looks like, and what the numbers did. One email a month, nothing in between.

Double opt-in — we send one confirmation link and nothing else until you click it.

BlockDex

Built by

Kynth Studios

the studio behind SkillWorks, RuleStack and ToolDrift

part of Toolproof, the measurement layer for AI agent tooling

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

© 2026 BlockDex. A Kynth Studios product. Changelog

BlockDex