A help icon. With a mouse it shows a tooltip on hover and keyboard focus, on touch devices and narrow screens it opens a bottom sheet with the same content and title. It ships no JavaScript: the tooltip is shown by CSS, the sheet is a native popover, and the (hover: hover) and (pointer: fine) media query plus a width breakpoint pick the mode. It works with JavaScript turned off.
Browser Support
Opens and closes the popup
Animates the initial appearance
Styles elements based on their contents
Positions the popup near its trigger
Styles the mobile popover backdrop
Animates the popover closing
Preview
Hover the icons. On a phone or in a narrow window they open a sheet instead.
Installation
Usage
import { ResponsiveHint } from "@/components/ui/responsive-hint"
export default function Price() {
return (
<span className="flex items-center gap-1.5">
Shipping
<ResponsiveHint title="How shipping is calculated">
The price depends on parcel weight and distance.
</ResponsiveHint>
</span>
)
}Examples
Always a sheet
mode="sheet" or mode="tooltip" turns the media query off.
<ResponsiveHint mode="sheet" title="Returns">
You can return the item within 30 days.
</ResponsiveHint>Custom icon and breakpoint
Any icon works as the trigger. breakpoint sets the width below which the sheet is used even with a mouse.
import { Info } from "lucide-react"
<ResponsiveHint side="right" icon={<Info />} breakpoint={1024}>
Below 1024px this becomes a sheet.
</ResponsiveHint>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | Hint content, the same in both modes |
| title | ReactNode | - | Heading. In the sheet it becomes the dialog title |
| icon | ReactNode | help icon | Trigger icon |
| breakpoint | number | 768 | Width in px below which the sheet is used |
| mode | "auto" | "tooltip" | "sheet" | "auto" | Force a mode instead of the media query |
| side | "top" | "right" | "bottom" | "left" | "top" | Tooltip side |
| align | "start" | "center" | "end" | "center" | Tooltip alignment |
| delayDuration | number | 150 | Hover delay before the tooltip shows, ms (transition-delay) |
| labels | { trigger?: string; close?: string; title?: string } | - | Texts: trigger (aria-label), close, title (hidden dialog title) |
| contentClassName | string | - | Classes for the tooltip or the sheet |
| className | string | - | Classes for the trigger |
Features
- Two modes: a CSS tooltip for mouse users, a popover bottom sheet for touch. Media queries pick the mode, so nothing jumps after hydration
- Accessible: the trigger is a button with aria-label and aria-describedby pointing to the tooltip. The sheet has a title, Escape and a tap outside close it, focus returns to the button
- Limits: Escape does not hide a tooltip opened by keyboard focus, move focus away instead. The content is rendered twice, so avoid ids inside children
- Reduced motion: the sheet appears without sliding