<x-widget.tooltip-cursor>
Tooltip cursor Blade component for Laravel and Livewire
A tooltip that follows the pointer over its element, for charts, maps and large areas where a label pinned to one edge would be far from what's pointed at. Moves to the other side of the pointer near the window's edges; with the keyboard it sits under the focused element; on a touch screen it sits above the finger, which slides it from one to the next once held, or shows it on a link or a button by a long press. Hidden on Esc, read out by screen readers, never clipped. For a label pinned to an element, see the tooltip. Works inside Livewire components.
php artisan bladewell:add tooltip-cursor
Usage
Livewire
Inside a Livewire component the text updates with each render, a showing one keeps following the pointer, and it stays linked to its element for screen readers.
<div class="flex h-40 items-end gap-2" wire:poll.10s="refresh">
@foreach ($days as $day)
<x-widget.tooltip-cursor wire:key="day-{{ $day->date }}" :text="$day->label.': '.$day->orders.' orders'" class="h-full flex-1 items-end">
{{-- your bar --}}
</x-widget.tooltip-cursor>
@endforeach
</div>
Examples
Area
Around anything larger: a card, an image, a region of a map. It follows the pointer anywhere over it, and keeps to the window, moving to the other side of the pointer near its right and bottom edges. Around a link or a button, keyboard focus shows it under the element, and on a touch screen a long press shows it above the finger without following the link.
Show code Hide code
<x-widget.tooltip-cursor text="Click to see the full-size photo" class="w-full max-w-72">
<a href="#photo" class="bg-field text-foreground/70 focus-visible:ring-primary grid h-40 w-full place-items-center rounded-2xl outline-none focus-visible:ring-2">
<x-widget.icon name="image" class="size-8" />
<span class="sr-only">Photo</span>
</a>
</x-widget.tooltip-cursor>
Chart
The usual place for it: the bars of a chart, each with its own reading that follows the pointer along it. A bar can't take focus, so the tooltip makes it focusable and names it with its text, so keyboard and screen reader users get each reading too.
Show code Hide code
<div class="flex h-40 items-end gap-2" role="list" aria-label="Orders this week">
{{-- Each bar's height as a class written out in full, so Tailwind sees it: a share of the busiest day. --}}
@foreach ([
'Mon' => ['orders' => 12, 'height' => 'h-[39%]'], 'Tue' => ['orders' => 19, 'height' => 'h-[61%]'],
'Wed' => ['orders' => 8, 'height' => 'h-[26%]'], 'Thu' => ['orders' => 23, 'height' => 'h-[74%]'],
'Fri' => ['orders' => 31, 'height' => 'h-full'], 'Sat' => ['orders' => 17, 'height' => 'h-[55%]'],
'Sun' => ['orders' => 6, 'height' => 'h-[19%]'],
] as $day => $bar)
<x-widget.tooltip-cursor :text="$day.': '.$bar['orders'].' orders'" role="listitem" class="h-full flex-1 items-end">
<span class="bg-primary/80 hover:bg-primary block w-full rounded-t-md transition-colors {{ $bar['height'] }}"></span>
</x-widget.tooltip-cursor>
@endforeach
</div>
Props
Other attributes, such as autocomplete or data-*, are passed through to the element. class styles the component's outer wrapper.
<x-widget.tooltip-cursor>
| Prop | Default | Description |
|---|---|---|
| text | Required | What it says: a short label or reading for what's under the pointer ("Tuesday: 14 orders"). |
| id |
null
|
Defaults to one made for it; the element inside points at it with aria-describedby. |
Accessibility
All 2 examples above are checked with axe-core against the WCAG 2.2 A and AA rules, in the light theme and the dark one, both as the page draws and with each popover, dialog, toast and tooltip opened, on every change. A change that fails can't be merged. Where axe can't decide, such as contrast on SVG text, the test measures the colours itself instead of letting it pass.
Automated checks can't judge everything: how it sounds in a screen reader, and how it feels to use from the keyboard, still need a person. Check those on your own pages too.
Source
What bladewell:add tooltip-cursor writes to your app with the default namespaces. Prefer to copy by hand? Take these files, plus the ones from
the components it also adds , and the theme and base CSS.
resources/views/components/widget/tooltip-cursor/index.blade.php Show
resources/js/widget/tooltip-cursor/index.js Show
app/View/Widget/ElementIds.php Show