react-floating-ui

A set of coding rules for building floating parts of React interfaces, such as tooltips, popovers, menus, dialogs, and selects, with React 19 and Floating UI.

In plain words
What is it for?
Use it while implementing or reviewing anchored React components, especially code that clones child elements or manages references.
Why use it?
It highlights compatibility problems and project conventions that can otherwise cause references and anchored components to work incorrectly.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/docs-plus/docs.plus/react-floating-ui
Clone the repo
git clone --depth 1 https://github.com/docs-plus/docs.plus

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,974 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.01974
Opus 5 $0.00000 $0.00987
Sonnet 5 $0.00000 $0.00395
Haiku 4.5 $0.00000 $0.00197

Measured 2d ago against content hash 5355c412f6de, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

react-floating-ui scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/react-floating-ui.mdc · 268 lines

How it starts

The opening of the file, as written. The whole thing — 268 lines — stays where its author put it; the contents beside it link to each section on GitHub.

React 19 + Floating UI — Project Conventions & Pitfalls

This project uses React 19.2, @floating-ui/react 0.27, daisyUI 5, and Tailwind CSS 4.


1. React 19: ref Is a Regular Prop (CRITICAL)

In React 19, ref moved from a special element field into element.props.ref. This breaks the common cloneElement + spread pattern silently.

The Bug

// ❌ BROKEN in React 19 — child.props.ref overwrites our ref
cloneElement(child, {
  ref: ourMergedRef,       // set first...
  ...child.props           // ...overwritten by child.props.ref!
})

The Fix

// ✅ CORRECT — strip ref, place merged ref LAST
const { ref: _, ...propsWithoutRef } = child.props ?? {}
cloneElement(child, getReferenceProps({
  ...propsWithoutRef,
  ref: mergedRef  // MUST come last to take precedence
}))

Reading a Child's Ref (React 18 + 19 compatible)

// Read from both locations for cross-version compatibility
const childRef = isValidElement(children)
  ? (children as any).props?.ref ?? (children as any).ref ?? null
  : null

Where This Applies

  • Tooltip.tsx — wraps arbitrary children via cloneElement
  • Popover.tsxPopoverTrigger asChild uses cloneElement
  • Any component using cloneElement with useMergeRefs

2. Floating UI: Use Built-in Interaction Hooks

Rule

NEVER reinvent hover/click/focus with manual useState + setTimeout. ALWAYS use Floating UI's interaction hooks.

Interaction Hook Example
Hover useHover(context, opts) Tooltip, HoverMenu
Click useClick(context, opts) Popover, Select
Dismiss useDismiss(context) All floating components
Role useRole(context, { role }) All (a11y)
Focus useFocus(context) Tooltip (keyboard a11y)

Why

Manual hover state management bypasses Floating UI's onOpenChange flow. This causes useDismiss, whileElementsMounted, and position calculation to be disconnected from the actual open state.

Read the full file on GitHub · 268 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 268 lines · 0 tokens per session scan A 5355c412f6de

Subscribe to this mod's changes

react-floating-ui is a cursor rule published in the GitHub repository docs-plus/docs.plus (88 stars, last pushed 4d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,974 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other cursor rules, from other repositories

rule-generating-agent

This rule is essential for maintaining consistency and quality in rule creation across the codebase. It must be followed whenever: (1) A user requests a new rule to be created, (2) An existing rule needs modification, (3) The user asks to remember certain behaviors or patterns, or (4) Future behavior changes are…

appboypov/pew-pew-cli · 1,197 tokens

ts-dependency-management-agent

Apply when adding, removing, or managing dependencies, or when structuring code modules in a TypeScript project, especially for CLIs. Promotes minimizing external dependencies, using lockfiles (package-lock.json), vetting dependencies, following SOLID principles for modular code, and using dependency injection for…

appboypov/pew-pew-cli · 62 tokens

ts-cli-command-definition-agent

Apply when defining or modifying CLI commands, subcommands, and options in a TypeScript project, particularly when using libraries like Commander.js or Yargs. Ensures use of robust parsing, POSIX-style flags, descriptive names, clear argument notation, and separation of parsing from implementation logic.

appboypov/pew-pew-cli · 57 tokens

angular-20

This rule provides comprehensive best practices and coding standards for Angular development, focusing on modern TypeScript, standalone components, signals, and performance optimizations.

angular/angular · 0 tokens

dev-standard

Apache Superset development standards and guidelines for Cursor IDE.

apache/superset · 1,147 tokens

typescript

Changes to these high-fan-out internals can affect every message, delta, element, or rerun. Keep work in them minimal, and benchmark changes with representative stress-test apps.

streamlit/streamlit · 4,669 tokens