Skip to content

Radix UI Popover Position Not Correct — Fix Alignment

DodaTech Updated 2026-06-24 1 min read

In this fix, you'll learn how to control Radix UI Popover positioning. This matters for tooltip and popover placement, and appears in dropdowns and floating menus.

The Problem

The following code demonstrates the typical mistake:

<Popover>
  <PopoverTrigger>Open</PopoverTrigger>
  <PopoverContent>
    Content here
  </PopoverContent>
</Popover>
// Popover may appear off-screen or in the wrong position

The Fix

Here is the corrected version:

<Popover>
  <PopoverTrigger asChild>
    <Button>Open</Button>
  </PopoverTrigger>
  <PopoverContent
    className="w-80"
    side="bottom"
    align="center"
    sideOffset={4}
  >
    Content here
  </PopoverContent>
</Popover>
// Popover appears correctly below and centered on the trigger

Prevention

  • Use side prop: 'top', 'bottom', 'left', 'right' for preferred placement.
  • Use align prop: 'start', 'center', 'end' for alignment relative to trigger.
  • Use sideOffset for spacing between trigger and popover (pixels).
  • Use alignOffset for fine-tuning alignment position.
  • Popover auto-flips to avoid viewport edges by default.

Common Mistakes with ui popover position

  1. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  2. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable
  3. Using head and tail instead of pattern matching, causing runtime errors on empty lists

These mistakes appear frequently in real-world RADIX code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### How does Radix UI handle popover positioning?

It uses floating-ui (formerly Popper) for positioning. It calculates the best position based on available space, auto-flipping to avoid viewport edges.

What is the asChild prop on PopoverTrigger?

It passes trigger props to the child element instead of rendering a default button. Use when you want a custom styled trigger element.

Can I disable auto-flipping?

Yes — set collisionPadding and avoidCollisions: false on PopoverContent. But this can cause the popover to render off-screen. Usually auto-flip is desired.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro