# KptTooltip (kptTooltip) A directive for a tooltip shown on hover/focus. Lightweight - the element is appended to `body` and positioned relative to the host (works in zoneless mode). Import: `import { KptTooltip } from '@konce-pt/angular';` ## Selector (attribute) `[kptTooltip]` ## Inputs - `kptTooltip`: string (the content, required) - empty content disables the tooltip - `kptTooltipPosition`: 'top'|'bottom'|'left'|'right' (default 'top') - the preferred side; see below - `kptTooltipOnlyWhenTruncated`: boolean (default false) - shows the tooltip only when the content does not fit the element (it is cut off with an ellipsis) ## Side The bubble goes on the first side that works, in this order: the preferred one, the opposite one, then the two others. A side works when the bubble fits in the viewport **and** the host's edge on that side is not covered - checked with `elementFromPoint` just inside the edge, so a button tucked under a sticky header gets its bubble below, not floating over the header. When no side works, the preferred one stays. The bubble is then clamped to the viewport (4 px margin), and `data-side` on it names the side that won. The check runs again on scroll and resize. ## A tooltip only for truncated text With `kptTooltipOnlyWhenTruncated` the tooltip does not repeat text that is visible anyway. Overflow is measured on the host **and on its direct children** - `text-overflow: ellipsis` usually sits on an inner element, and such an element shrinks to the available width without stretching its parent, so measuring the host alone would detect nothing. When the text is deeper than one level, put the directive on its direct parent. The check happens at hover (or focus) time, not at render - so the result is always current after a change in width, zoom or layout, with no `ResizeObserver`. {{ name }} ## Example Save ? ## Accessibility - The bubble appears on hover and on keyboard focus. Focus is tracked with `focusin`/`focusout`, so it also works when the focus lands on an inner element (`kpt-button`, `kpt-icon-button`). - The text reaches screen readers through a persistent, hidden description linked with `aria-describedby` to the element that actually takes focus (the bubble itself only exists while shown). It is skipped when it would repeat the element's name (an icon button whose label equals the tooltip) and with `onlyWhenTruncated`, where the text is already in the DOM; the visible bubble is then `aria-hidden`. - `Escape` closes the bubble, and the pointer can move onto it without it disappearing (a 120 ms grace period) - WCAG 1.4.13. - It does NOT replace an accessible name - an icon-only button still needs its own label. ## Tokens Background `--kpt-color-on-surface`, text `--kpt-color-surface` (contrast in both themes), `--kpt-elevation-2`. ## Styling and the top layer The bubble is styled by `.kpt-tooltip` from `@konce-pt/styles`, in the `kpt.components` layer - override it from your own CSS without `!important`; only `position: fixed` and the coordinates stay inline. Inside an open `` or popover the bubble is attached to that element, because a modal dialog lives in the top layer and anything outside it is hidden behind it regardless of `z-index`. A hover shows the bubble after 300 ms (sliding across a toolbar does not light every icon); focus shows it at once. Changing the text while the bubble is visible updates it.