pub struct Popover<S> { /* private fields */ }Expand description
A panel opened by a button beside it.
It sits on a page whose signals are S.
Declare one as a const from a NodeRef that
node_ref! declares, and use the same value for
the button and the panel, so they agree on the panel’s id, which is the
node ref’s name. The panel is a popover="auto" with role="dialog",
named by its button, and the button opens and closes it through invoker
commands with aria-haspopup="dialog". The browser puts the panel above
the page, closes it on Escape or on a click outside, and returns focus to
the button when focus was inside it. Focus stays on the button as the
panel opens, so place the panel right after its button, where Tab moves
from the button into it.
The panel is placed under the button with CSS anchor positioning and
flips above it where there is no room below. The panel carries the node
ref, so placing one popover twice on a page makes
Page::render panic. Close it from a statement
with NodeRef::hide_popover on the same node ref.
use hypersig::html::p;
use hypersig::{NodeRef, Signals};
use hypersig_ui::{ButtonSize, ButtonVariant, Popover};
use serde::{Deserialize, Serialize};
#[derive(Signals, Serialize, Deserialize)]
struct Profile {}
hypersig::node_ref!(const DETAILS: NodeRef<Profile>);
const INFO: Popover<Profile> = Popover::new(DETAILS);
let open = INFO.trigger(ButtonVariant::Outline, ButtonSize::Default).text("Details");
let panel = INFO.popover().child(p().text("Joined in 2024."));
assert!(open.render().contains(r#"command="toggle-popover""#));
assert!(panel.render().contains(r#"popover="auto""#));