Skip to main content

Tooltip

Struct Tooltip 

Source
pub struct Tooltip<S> { /* private fields */ }
Expand description

A tooltip on a page whose signals are S, describing the button it is attached to.

Declare one as a const and use the same value for the button and the tooltip, so they agree on the tooltip’s id. It follows the WAI-ARIA tooltip pattern: the tooltip has role="tooltip" and the button aria-describedby pointing at it, so a screen reader reads the text after the button’s name. It opens while the pointer is on the button or the tooltip, or the button has focus, and closes when both are left or a key is pressed on the button.

The tooltip is a popover="hint", which the browser closes on Escape without closing an open menu. browser-compat-data 8.1.6 lists hint popovers for Chrome 151 and Firefox 153, an older partial version for Chrome 133 to 150 and Firefox 149 to 152, and Safari only in its preview. A browser without them treats the value as manual, and there Escape closes the tooltip only while focus is on its button.

The button carries the attributes the tooltip needs, so build it here rather than adding a tooltip to a button made elsewhere. The tooltip carries a node ref with its name, so two tooltips with one name on a page make Page::render panic.

use hypersig::Signals;
use hypersig_ui::{ButtonVariant, Tooltip};
use serde::{Deserialize, Serialize};

#[derive(Signals, Serialize, Deserialize)]
struct Editor {}

const BOLD: Tooltip<Editor> = Tooltip::new("bold-tip");

let button = BOLD.icon_trigger(ButtonVariant::Outline, "Bold").text("B");
let tip = BOLD.tooltip("Ctrl+B");
assert!(button.render().contains(r#"aria-describedby="bold-tip""#));
assert!(tip.render().contains(r#"role="tooltip""#));

Implementations§

Source§

impl<S> Tooltip<S>

Source

pub const fn new(name: &'static str) -> Self

A tooltip whose id is name.

§Panics

Panics if name is empty or holds a character other than an ASCII letter, digit, -, or _. In a const, that is a compile error.

Source

pub fn trigger(self, variant: ButtonVariant, size: ButtonSize) -> El<S>

A button described by the tooltip.

Source

pub fn icon_trigger( self, variant: ButtonVariant, label: impl Into<String>, ) -> El<S>

An icon button named label and described by the tooltip.

Source

pub fn tooltip(self, text: impl Into<String>) -> El<S>

The tooltip, holding text.

Trait Implementations§

Source§

impl<S> Clone for Tooltip<S>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S> Copy for Tooltip<S>

Source§

impl<S> Debug for Tooltip<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> Freeze for Tooltip<S>

§

impl<S> RefUnwindSafe for Tooltip<S>

§

impl<S> Send for Tooltip<S>

§

impl<S> Sync for Tooltip<S>

§

impl<S> Unpin for Tooltip<S>

§

impl<S> UnsafeUnpin for Tooltip<S>

§

impl<S> UnwindSafe for Tooltip<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.