Skip to content

popover: Add offset and optional anchor-aligned arrows - #3145

Merged
huacnlee merged 3 commits into
mainfrom
feat/popover-options
Sep 20, 2026
Merged

huacnlee merged 3 commits into
mainfrom
feat/popover-options

Conversation

@huacnlee

@huacnlee huacnlee commented Sep 20, 2026

Copy link
Copy Markdown
Member

Description

Popover now supports anchor + offset + arrow: callers can adjust the trigger gap and enable an arrow aligned to any of the eight existing anchors, including TopCenter and BottomCenter. The arrow follows the anchor's edge and leading/center/trailing alignment, with an inset to avoid rounded corners. arrow defaults to false; spacing and arrows preserve the selected anchor and its window-clamping behavior.

Popover::new("details")
    .anchor(Anchor::TopCenter)
    .offset(px(8.))
    .arrow(true)
    .trigger(Button::new("details-trigger").label("Details"))
    .child("Popover content")

Correct the documentation: Anchor::TopLeft names the popup's own anchor and opens below the trigger. Positioning measures the actual trigger rectangle and uses current-frame bounds when the trigger moves. The compact Anchor story demonstrates all eight anchors with small trigger buttons and a shared Arrow checkbox, unchecked by default. English and Chinese docs are updated.

Public API

gpui-component

  • popover::Popover::offset(self, offset: impl Into<Pixels>) -> Self — set the trigger-to-surface gap, or trigger-to-arrow-tip gap; defaults to 0.25rem.
  • popover::Popover::arrow(self, arrow: bool) -> Self — show the themed arrow aligned to the existing anchor; defaults to false.

gpui-base

  • Popover::offset(self, offset: Pixels) -> Self and Popup::offset(self, offset: Pixels) -> Self — set the outward gap for the selected anchor; defaults to zero.
  • Popover::on_position(self, callback: impl Fn(ResolvedPosition, Bounds<Pixels>) + 'static) -> Self and Popup::on_position(self, callback: impl Fn(ResolvedPosition, Bounds<Pixels>) + 'static) -> Self — observe resolved popup and trigger geometry before content prepaint for custom presentation.
  • Positioner::on_position(self, callback: impl Fn(ResolvedPosition) + 'static) -> Self — observe resolved geometry before children prepaint.

No new Popover placement/alignment API, enum re-exports, JavaScript methods, or TypeScript declarations. Base supplies geometry; Component draws the arrow.

Breaking Changes

The existing horizontal-center anchors now attach to the corresponding trigger edge instead of using the old top-left fallback:

- .anchor(Anchor::LeftCenter)  // Legacy top-left fallback
+ .anchor(Anchor::LeftCenter)  // Right of the trigger, vertically centered
- .anchor(Anchor::RightCenter) // Legacy top-left fallback
+ .anchor(Anchor::RightCenter) // Left of the trigger, vertically centered

The six top/bottom anchors retain their default positioning. Anchors clamp into the window without flipping.

How to Test

  • cargo test -p gpui-base -p gpui-component --lib --locked — 1,548 tests passed.
  • cargo clippy -p gpui-base -p gpui-component --lib --locked
  • cargo build -p gpui-component-story -p gpui-base-examples --bins --locked
  • cargo run -p gpui-component-story -- Popover: in the final Anchor section, toggle the Arrow checkbox and click each anchor button. Check leading, center, and trailing arrow alignment and spacing, with and without arrows.
  • cargo run -p gpui-base-examples -- popover: exercise the unstyled popover lifecycle.

Regression coverage includes eight anchor positions, explicit gaps, moving triggers, no implicit flipping, arrow anchor alignment, joins, and default positioning. Native testing was on Linux; macOS and Windows were not tested locally.

Checklist

  • Read and followed CONTRIBUTING.md.
  • Reviewed the changes, including AI-generated code.
  • Built and ran the affected Popover story on Linux.

@huacnlee huacnlee changed the title popover: Add side placement, offset, and optional arrows popover: Add anchor-aligned arrows and configurable offset Sep 20, 2026
@huacnlee huacnlee changed the title popover: Add anchor-aligned arrows and configurable offset popover: Add offset and optional anchor-aligned arrows Sep 20, 2026
@huacnlee huacnlee added this to the 0.7.0 milestone Sep 20, 2026
@huacnlee
huacnlee enabled auto-merge (squash) September 20, 2026 15:01
@huacnlee
huacnlee merged commit cfc37e6 into main Sep 20, 2026
12 checks passed
@huacnlee
huacnlee deleted the feat/popover-options branch September 20, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant