pub struct Tooltip { /* private fields */ }Expand description
§Tooltip component
Tooltip which is automatically shown when an element is focused or hovered.
Bootstrap’s tooltips depend on Popper, which assumes complete control
of the DOM. Yew also assumes complete control of the DOM, so this can lead
to unexpected behaviour whenever it reuses DOM components – so you can’t
just use data-bs-toggle="tooltip".
This component is similar to react-bootstrap’s Tooltip component –
it wires up Popper in a way that works nicely with Yew.
There are some similarities and differences between this component and Bootstrap’s in-built implementation:
-
There’s no need to use
bootstrap.bundle.min.jsorpopper.min.js. This component usespopper-rs, which comes with Popper. -
You can’t trigger or describe tooltips with
data-bs-*attributes. -
The
<Tooltip>’s content is set with thechildrenproperty, which supports arbitrary HTML.It doesn’t support the
sanitize,sanitizeFnortitleattributes. -
Like Bootstrap,
<Tooltip>is triggered by input focus and mouse hover by default.These triggers can be individually disabled, and you can control display manually instead.
<Tooltip>does not support theclicktrigger – use input focus instead. This makes it possible to trigger tooltips when there is no pointing device available or it cannot be used. -
Like Bootstrap, tooltips exist in a shadow DOM (portal) outside of the normal page hierarchy.
Unlike Bootstrap, the
<Tooltip>is always present in the DOM, even when the tooltip is not displayed.A
<Tooltip>needs to remain part of the DOM if it could be shown in a component. Use theshowanddisabledproperties to control its display. -
When using a
targetwhich could bedisabledand triggering on focus and/or on hover, you can prevent the tooltip from being displayed by setting thedisabledproperty on the on the<Tooltip>as well. Otherwise, thetargetwon’t fire an event to hide the tooltip when it loses focus or isn’t hovered.If you only ever trigger tooltips manually, then there’s no need to sync the
disabledstate. -
Like Bootstrap, if you want the tooltip to be displayed on focus or on hover on a
disabledtarget, you’ll need to use a wrapper element.
§Examples
Button with a tooltip, shown automatically on focus or hover:
use yew::prelude::*;
use yew_bootstrap::component::{Button, Tooltip};
use yew_bootstrap::util::Color;
fn test() -> Html {
let btn_ref = NodeRef::default();
html! {
<>
<Button style={Color::Primary} node_ref={btn_ref.clone()}>
{"Button with tooltip"}
</Button>
<Tooltip target={btn_ref}>
{"Tooltip for button."}
</Tooltip>
</>
}
}Trait Implementations§
Source§impl BaseComponent for Tooltipwhere
Self: 'static,
impl BaseComponent for Tooltipwhere
Self: 'static,
Source§type Properties = TooltipProps
type Properties = TooltipProps
Source§fn update(&mut self, _ctx: &Context<Self>, _msg: Self::Message) -> bool
fn update(&mut self, _ctx: &Context<Self>, _msg: Self::Message) -> bool
Source§fn changed(
&mut self,
_ctx: &Context<Self>,
_old_props: &Self::Properties,
) -> bool
fn changed( &mut self, _ctx: &Context<Self>, _old_props: &Self::Properties, ) -> bool
Source§fn view(&self, ctx: &Context<Self>) -> HtmlResult
fn view(&self, ctx: &Context<Self>) -> HtmlResult
Source§fn rendered(&mut self, _ctx: &Context<Self>, _first_render: bool)
fn rendered(&mut self, _ctx: &Context<Self>, _first_render: bool)
Source§fn prepare_state(&self) -> Option<String>
fn prepare_state(&self) -> Option<String>
Source§impl FunctionProvider for Tooltip
impl FunctionProvider for Tooltip
Source§type Properties = TooltipProps
type Properties = TooltipProps
Source§fn run(ctx: &mut HookContext, props: &Self::Properties) -> HtmlResult
fn run(ctx: &mut HookContext, props: &Self::Properties) -> HtmlResult
Auto Trait Implementations§
impl !Freeze for Tooltip
impl !RefUnwindSafe for Tooltip
impl !Send for Tooltip
impl !Sync for Tooltip
impl Unpin for Tooltip
impl !UnwindSafe for Tooltip
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoPropValue<Option<T>> for T
impl<T> IntoPropValue<Option<T>> for T
Source§fn into_prop_value(self) -> Option<T>
fn into_prop_value(self) -> Option<T>
self to a value of a Properties struct.Source§impl<T> IntoPropValue<T> for T
impl<T> IntoPropValue<T> for T
Source§fn into_prop_value(self) -> T
fn into_prop_value(self) -> T
self to a value of a Properties struct.