Tooltip component provides context or additional information for the element it is attached to.
import { Button, Tooltip } from "@kesko/components";
import { IconQuestion } from "@kesko/iconography/react";
export default () => (
<>
<Button appearance="text" square className="k-cursor-help" aria-describedby="delivery-help">
<IconQuestion label="About delivery times" />
</Button>
<Tooltip id="delivery-help" defaultOpen>
Orders placed before noon are delivered the same day.
</Tooltip>
</>
);<button class="k-button k-cursor-help" appearance="text" square type="button" aria-describedby="delivery-help">
<svg viewBox="0 0 24 24" role="img" aria-label="About delivery times" xmlns="http://www.w3.org/2000/svg"><path d="M13.088 11.78c-.34.325-.523.55-.538 1.145-.015.142-.07.255-.24.282l-.762.128c-.17.027-.268-.07-.283-.24l-.058-.75c-.112-1.568 1.808-1.963 1.823-3.065 0-.537-.437-.848-1.157-.848-.65 0-1.258.255-1.865.635-.17.1-.31.043-.395-.127l-.423-.89c-.085-.17-.07-.298.113-.425.635-.425 1.637-.79 2.74-.79 1.625 0 2.852.875 2.852 2.275s-1.172 2.063-1.807 2.67zm-1.2 2.98c-.735 0-1.23.522-1.23 1.188s.495 1.2 1.23 1.2 1.23-.523 1.23-1.2-.495-1.188-1.23-1.188zm8.137-8.717a.396.396 0 0 0-.603-.048l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg>
</button>
<k-tooltip id="delivery-help" role="tooltip" popover="manual">Orders placed before noon are delivered the same day.</k-tooltip>
<script type="module">
import "@kesko/components/vanilla";
</script>import { Button, Tooltip } from "@kesko/components";
import { IconQuestion } from "@kesko/iconography/react";
export default () => (
<>
<Button appearance="text" square className="k-cursor-help" aria-describedby="loyalty-help">
<IconQuestion label="About Plussa points" />
</Button>
<Tooltip
id="loyalty-help"
style={{
"--k-tooltip-bg": "var(--k-color-bg-inverted)",
"--k-tooltip-text": "var(--k-color-text-inverted)",
"--k-tooltip-radius": "var(--k-radius-sm)",
}}
>
Plussa points are added to your account within two days.
</Tooltip>
</>
);<button class="k-button k-cursor-help" appearance="text" square type="button" aria-describedby="loyalty-help">
<svg viewBox="0 0 24 24" role="img" aria-label="About Plussa points" xmlns="http://www.w3.org/2000/svg"><path d="M13.088 11.78c-.34.325-.523.55-.538 1.145-.015.142-.07.255-.24.282l-.762.128c-.17.027-.268-.07-.283-.24l-.058-.75c-.112-1.568 1.808-1.963 1.823-3.065 0-.537-.437-.848-1.157-.848-.65 0-1.258.255-1.865.635-.17.1-.31.043-.395-.127l-.423-.89c-.085-.17-.07-.298.113-.425.635-.425 1.637-.79 2.74-.79 1.625 0 2.852.875 2.852 2.275s-1.172 2.063-1.807 2.67zm-1.2 2.98c-.735 0-1.23.522-1.23 1.188s.495 1.2 1.23 1.2 1.23-.523 1.23-1.2-.495-1.188-1.23-1.188zm8.137-8.717a.396.396 0 0 0-.603-.048l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg>
</button>
<k-tooltip id="loyalty-help" role="tooltip" popover="manual" style="--k-tooltip-bg: var(--k-color-bg-inverted); --k-tooltip-text: var(--k-color-text-inverted); --k-tooltip-radius: var(--k-radius-sm)">Plussa points are added to your account within two days.</k-tooltip>
<script type="module">
import "@kesko/components/vanilla";
</script>import { Button, Tooltip } from "@kesko/components";
import { IconQuestion } from "@kesko/iconography/react";
export default () => (
<>
<Button appearance="text" square className="k-cursor-help" aria-describedby="pickup-help">
<IconQuestion label="About pickup" />
</Button>
<Tooltip id="pickup-help" position="bottom" open>
Pickup orders are ready two hours after checkout.
</Tooltip>
</>
);<button class="k-button k-cursor-help" appearance="text" square type="button" aria-describedby="pickup-help">
<svg viewBox="0 0 24 24" role="img" aria-label="About pickup" xmlns="http://www.w3.org/2000/svg"><path d="M13.088 11.78c-.34.325-.523.55-.538 1.145-.015.142-.07.255-.24.282l-.762.128c-.17.027-.268-.07-.283-.24l-.058-.75c-.112-1.568 1.808-1.963 1.823-3.065 0-.537-.437-.848-1.157-.848-.65 0-1.258.255-1.865.635-.17.1-.31.043-.395-.127l-.423-.89c-.085-.17-.07-.298.113-.425.635-.425 1.637-.79 2.74-.79 1.625 0 2.852.875 2.852 2.275s-1.172 2.063-1.807 2.67zm-1.2 2.98c-.735 0-1.23.522-1.23 1.188s.495 1.2 1.23 1.2 1.23-.523 1.23-1.2-.495-1.188-1.23-1.188zm8.137-8.717a.396.396 0 0 0-.603-.048l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg>
</button>
<k-tooltip id="pickup-help" position="bottom" open role="tooltip" popover="manual">Pickup orders are ready two hours after checkout.</k-tooltip>
<script type="module">
import "@kesko/components/vanilla";
</script>import { Button, Grid, Tooltip } from "@kesko/components";
const positions = [
"top-start",
"top",
"top-end",
"bottom-start",
"bottom",
"bottom-end",
"start-top",
"start",
"start-bottom",
"end-top",
"end",
"end-bottom",
] as const;
export default () => (
<Grid columns={3} gap="xs">
{positions.map(position => {
const id = `position-${position}`;
return (
<div key={id}>
<Button size="sm" appearance="outline" expand className="k-cursor-help" aria-describedby={id}>
{position}
</Button>
<Tooltip id={id} position={position}>
Opens at {position}. Longer text grows the bubble away from the arrow.
</Tooltip>
</div>
);
})}
</Grid>
);<k-grid columns="3" gap="xs">
<div>
<button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-top-start">top-start</button>
<k-tooltip id="position-top-start" position="top-start" role="tooltip" popover="manual">Opens at top-start. Longer text grows the bubble away from the arrow.</k-tooltip>
</div>
<div>
<button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-top">top</button>
<k-tooltip id="position-top" role="tooltip" popover="manual">Opens at top. Longer text grows the bubble away from the arrow.</k-tooltip>
</div>
<div>
<button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-top-end">top-end</button>
<k-tooltip id="position-top-end" position="top-end" role="tooltip" popover="manual">Opens at top-end. Longer text grows the bubble away from the arrow.</k-tooltip>
</div>
<div>
<button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-bottom-start">bottom-start</button>
<k-tooltip id="position-bottom-start" position="bottom-start" role="tooltip" popover="manual">Opens at bottom-start. Longer text grows the bubble away from the arrow.</k-tooltip>
</div>
<div>
<button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-bottom">bottom</button>
<k-tooltip id="position-bottom" position="bottom" role="tooltip" popover="manual">Opens at bottom. Longer text grows the bubble away from the arrow.</k-tooltip>
</div>
<div>
<button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-bottom-end">bottom-end</button>
<k-tooltip id="position-bottom-end" position="bottom-end" role="tooltip" popover="manual">Opens at bottom-end. Longer text grows the bubble away from the arrow.</k-tooltip>
</div>
<div>
<button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-start-top">start-top</button>
<k-tooltip id="position-start-top" position="start-top" role="tooltip" popover="manual">Opens at start-top. Longer text grows the bubble away from the arrow.</k-tooltip>
</div>
<div>
<button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-start">start</button>
<k-tooltip id="position-start" position="start" role="tooltip" popover="manual">Opens at start. Longer text grows the bubble away from the arrow.</k-tooltip>
</div>
<div>
<button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-start-bottom">start-bottom</button>
<k-tooltip id="position-start-bottom" position="start-bottom" role="tooltip" popover="manual">Opens at start-bottom. Longer text grows the bubble away from the arrow.</k-tooltip>
</div>
<div>
<button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-end-top">end-top</button>
<k-tooltip id="position-end-top" position="end-top" role="tooltip" popover="manual">Opens at end-top. Longer text grows the bubble away from the arrow.</k-tooltip>
</div>
<div>
<button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-end">end</button>
<k-tooltip id="position-end" position="end" role="tooltip" popover="manual">Opens at end. Longer text grows the bubble away from the arrow.</k-tooltip>
</div>
<div>
<button class="k-button k-button-sm k-cursor-help" appearance="outline" expand type="button" aria-describedby="position-end-bottom">end-bottom</button>
<k-tooltip id="position-end-bottom" position="end-bottom" role="tooltip" popover="manual">Opens at end-bottom. Longer text grows the bubble away from the arrow.</k-tooltip>
</div>
</k-grid>
<script type="module">
import "@kesko/components/vanilla";
</script>import { Button, Tooltip } from "@kesko/components";
import { IconQuestion } from "@kesko/iconography/react";
export default () => (
<>
<Button appearance="text" square className="k-cursor-help" aria-describedby="returns-help">
<IconQuestion label="About returns" />
</Button>
<Tooltip id="returns-help" arrow={false}>
Returns are free for 30 days.
</Tooltip>
</>
);<button class="k-button k-cursor-help" appearance="text" square type="button" aria-describedby="returns-help">
<svg viewBox="0 0 24 24" role="img" aria-label="About returns" xmlns="http://www.w3.org/2000/svg"><path d="M13.088 11.78c-.34.325-.523.55-.538 1.145-.015.142-.07.255-.24.282l-.762.128c-.17.027-.268-.07-.283-.24l-.058-.75c-.112-1.568 1.808-1.963 1.823-3.065 0-.537-.437-.848-1.157-.848-.65 0-1.258.255-1.865.635-.17.1-.31.043-.395-.127l-.423-.89c-.085-.17-.07-.298.113-.425.635-.425 1.637-.79 2.74-.79 1.625 0 2.852.875 2.852 2.275s-1.172 2.063-1.807 2.67zm-1.2 2.98c-.735 0-1.23.522-1.23 1.188s.495 1.2 1.23 1.2 1.23-.523 1.23-1.2-.495-1.188-1.23-1.188zm8.137-8.717a.396.396 0 0 0-.603-.048l-.505.505a.399.399 0 0 0-.035.52 8.45 8.45 0 0 1 1.62 4.982c0 4.688-3.812 8.5-8.5 8.5S3.5 16.687 3.5 12 7.313 3.5 12 3.5c1.86 0 3.58.602 4.983 1.62.16.117.38.105.52-.035l.505-.505a.4.4 0 0 0-.048-.603A9.945 9.945 0 0 0 12 2.002c-5.515 0-10 4.485-10 10s4.485 10 10 10 10-4.485 10-10c0-2.23-.735-4.292-1.975-5.957z" fill="currentColor" /></svg>
</button>
<k-tooltip id="returns-help" arrow="false" role="tooltip" popover="manual">Returns are free for 30 days.</k-tooltip>
<script type="module">
import "@kesko/components/vanilla";
</script>Properties #
| Name | Description | Type | Default |
|---|---|---|---|
id | The id that triggers point at. Any element whose | string | — |
position | The side of the trigger the tooltip opens on, and optionally which edge of the tooltip the arrow sits at. | "top" | "top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "start" | "start-top" | "start-bottom" | "end" | "end-top" | "end-bottom" | "top" |
arrow | Shows the arrow that points at the trigger. | boolean | true |
delay | Milliseconds the pointer rests on the trigger before the tooltip opens. Keyboard focus and clicking or tapping the trigger open it right away. | number | 300 |
defaultOpen | Shows the tooltip as soon as it mounts, as a one-time hint. It closes like any other tooltip and then follows hover and focus. | boolean | false |
open | Keeps the tooltip open regardless of hover and focus, for example in a showcase. Leave it out for a tooltip that people trigger themselves. | boolean | — |
Styles #
CSS custom properties provide finer-grained control than properties. See Styling API for more details. Prefer the Properties API when it suits your need.
| Name | Description | Default |
|---|---|---|
--k-tooltip-bg | Overrides the background color. | var(--k-color-bg-base) |
--k-tooltip-text | Overrides the text color. | var(--k-color-text-base) |
--k-tooltip-radius | Overrides the border radius. | var(--k-radius-lg) |
--k-tooltip-shadow | Overrides the shadow of the bubble. The arrow keeps a small shadow of its own. | var(--k-shadow-float) |
--k-tooltip-max-size | Overrides the maximum width. The tooltip hugs its text up to this. | 15rem |
Accessibility #
Tooltip is built on a <k-tooltip> element with role="tooltip". The trigger points at it with aria-describedby, so a screen reader reads the tooltip text right after the trigger’s name.
- The trigger needs a name of its own. A tooltip describes, it does not label. An icon-only button gets its name from the icon’s
labelor fromaria-label, and the tooltip adds detail on top. Never use thetitleattribute instead. - Only focusable elements can trigger it. Keyboard users reach the tooltip through focus, so put
aria-describedbyon a button, link or form control, not on a plain icon or span. - Plain text only. A tooltip disappears when the pointer leaves, so people cannot interact with anything inside it. Links, buttons and formatted content belong in a popover.
- Never put essential information in a tooltip. Touch users cannot hover, and the text is easy to miss. Say what matters in the interface and use the tooltip for a hint.
- Dismissing is handled for you. The tooltip stays open while hovered, closes on
Escor a click elsewhere, and opens on tap. - One at a time. Opening a tooltip closes any other tooltip on the page, so the screen never fills up with hints.
- Check contrast if you override colors.
--k-tooltip-textneeds 4.5:1 against--k-tooltip-bg. Verify with the WebAIM contrast checker.
See the accessibility guidelines and the A11Y checklist for more details.
Usage #
There are two necessary parts to using the Tooltip component. The @kesko/components package and the CSS Framework are required. Everything else is optional:
npm install @kesko/components @kesko/csspnpm add @kesko/components @kesko/cssyarn add @kesko/components @kesko/cssbun add @kesko/components @kesko/cssOnce installed, load the CSS Framework in your app’s entry point or root layout:
import "@kesko/css";Then, you can import the Tooltip:
import { Tooltip } from "@kesko/components";Projects without React can get the same styles from @kesko/css by importing the components stylesheet as well:
@import "@kesko/css";
@import "@kesko/css/components";Resources #
Usage guidelines
Learn how to use the component library with React, Next.js, or basic HTML.
Localization
How to translate the components for multiple languages.
CSS Framework
Utilities and tokens for everything the components don’t cover.
Themes
How to customize the component library theme.
Accessibility checklist
Interactive, browser-based Kesko accessibility checklist.