Popover
An anchored floating surface with controlled or internally managed open state.
Like every gpui-base primitive, Popover supplies behavior and semantic structure without imposing a product visual language. Apply GPUI styles and compose the exported parts to match your design system.
Example
The single native Cargo entrypoint selects this primitive from the shared showcase implementation. The same showcase is compiled once for the WASM preview above.
cargo run -p gpui-base --example components -- popoverImport
use gpui_base::{Popover};Anatomy and API
The example composes Popover. GPUI's standard styling and event traits provide presentation; these base types provide the interaction structure.
The authoritative module is components/popover.rs. Native and browser previews compile this same file.
State and events
Open state can be parent-controlled; activation, outside click, and Escape request lifecycle changes.
Keep controlled state on the parent render type or in a GPUI entity. Update it in callbacks and call cx.notify(); do not recreate persistent entities during every render.
Complete Rust example
The complete implementation used by the runnable showcase is embedded directly from Rust source:
use gpui::{InteractiveElement as _, IntoElement, ParentElement as _, Styled as _, div, relative};
use gpui_base::{Button, Popover};
use super::super::BaseShowcase;
impl BaseShowcase {
pub(in super::super) fn popover(&self) -> impl IntoElement {
Popover::new("example-popover")
.trigger(
Button::new("popover-trigger")
.h_7()
.line_height(relative(1.))
.px_3()
.flex()
.items_center()
.justify_center()
.bg(gpui::black())
.text_color(gpui::white())
.child("Open Popover"),
)
.content(|_, _, cx| {
let state = cx.entity().downgrade();
div()
.id("popover-content")
.w_64()
.p_2()
.flex()
.flex_col()
.gap_2()
.text_xs()
.bg(super::example_rgb(0xffffff))
.border_1()
.border_color(super::example_rgb(0xd4d4d4))
.child("Workspace access")
.child(
div()
.text_xs()
.text_color(super::example_rgb(0x737373))
.child("Anyone with the link can view."),
)
.child(
div().mt_1().flex().justify_end().child(
Button::new("popover-done")
.h_7()
.line_height(relative(1.))
.px_3()
.flex()
.items_center()
.justify_center()
.bg(gpui::black())
.text_color(gpui::white())
.on_click(move |_, window, cx| {
_ = state.update(cx, |state, cx| state.dismiss(window, cx));
})
.child("Done"),
),
)
})
}
}The command above supplies application initialization, window creation, and shared BaseShowcase state.
Accessibility
Support Escape/outside dismissal and return focus; move focus only when its content requires it.
Notes
Use stable element IDs where accepted. Verify focus, hover, active, selected, disabled, reduced-motion, and high-contrast appearances in the consuming design system.