Extra detail about a control, on hover and on focus, built on the Popover API.
<div class="cap-specimen-row">
<button type="button" class="cap-btn" data-cap-tip="tip-retry" id="sample-retry">Retry job</button>
<div class="cap-popover" data-cap="tooltip" id="tip-retry" popover="manual" role="tooltip" data-variant="tooltip" data-side="top">Runs job_7c21 again with the same inputs. Its last run failed at 14:02.<span class="cap-popover-arrow" aria-hidden="true"></span></div>
<button type="button" class="cap-btn" id="sample-next">Cancel job</button>
</div>
import "capsomer/tokens.css";
import { Tooltip } from "capsomer/react/tooltip";
Usage
<button type="button" class="cap-btn" data-cap-tip="tip-retry">Retry job</button>
<div class="cap-popover" data-cap="tooltip" id="tip-retry" popover="manual" role="tooltip" data-variant="tooltip" data-side="top">Runs job_7c21 again with the same inputs. <kbd>R</kbd><span class="cap-popover-arrow" aria-hidden="true"></span></div>
<Tooltip tip="Runs job_7c21 again with the same inputs." side="top" arrow>
{(t) => <button type="button" className="cap-btn" {...t}>Retry job</button>}
</Tooltip>
<div class="cap-specimen-row">
<p>Checks for <a href="#s-focus" data-cap-tip="tip-site" data-specimen-open>example.com</a> are failing.</p>
<div class="cap-popover" data-cap="tooltip" id="tip-site" popover="manual" role="tooltip" data-variant="tooltip" data-side="bottom">3 failed checks since 13:40. It last answered at 14:02.<span class="cap-popover-arrow" aria-hidden="true"></span></div>
</div>
Wires one trigger to its tip: the tip gets the popover surface (cap-popover, the tooltip variant), popover="manual" and role="tooltip", and the trigger aria-describedby. Returns a function that unwires it.
showTip
(trigger: HTMLElement): void
Shows or hides the tip of a trigger that is attached.
hideTip
(trigger: HTMLElement): void
enhance
(root?: ParentNode): () => void
Attaches to every [data-cap-tip] trigger under root not yet attached; the attribute's value is the id of its tip. Returns a function that detaches.
Accessibility
Key
Does
Tab to the trigger
Shows the tip at once
Esc
Hides the tip; focus stays on the trigger
Tab away (blur)
Hides the tip
The trigger keeps its own name; the tip is its description.
Tip text is --text on --raised, far above 4.5:1 in both themes; its edge is 3:1 against the page.
Touch: there is no hover, so a tip's detail must never be needed.