Tooltip
A short label shown when the pointer rests on a control or the keyboard reaches it. In the look of the app's style.
Usage
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScTooltip, ScTooltipArrow, ScTooltipPortal, ScTooltipProvider, ScTooltipTrigger,} from '@semantic-components/ui';
@Component({ selector: 'app-tooltip-usage-demo', imports: [ ScButton, ScTooltip, ScTooltipArrow, ScTooltipPortal, ScTooltipProvider, ScTooltipTrigger, ], template: ` <div scTooltipProvider> <button scButton scTooltipTrigger variant="outline">Hover</button> <ng-template scTooltipPortal> <div scTooltip> Add to library <span scTooltipArrow></span> </div> </ng-template> </div> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class TooltipUsageDemo {}Anatomy
Every part is a directive on your element; the trigger, the content (text, a kbd…) and the arrow are yours.
import { ScTooltipProvider, ScTooltipTrigger, ScTooltipPortal, ScTooltip, ScTooltipArrow, ScTooltipGroup,} from '@semantic-components/ui';<div scTooltipProvider side="…"> <button scButton scTooltipTrigger>…</button> <ng-template scTooltipPortal> <div scTooltip> … <span scTooltipArrow></span> </div> </ng-template></div>Accessibility
- A tooltip is a visual aid: name the trigger itself (its text, or sr-only text). It is read as the trigger's description (role="tooltip", aria-describedby) while open.
- Keyboard focus opens it at once; Escape, blur or a click closes it. The pointer can move onto it without closing it.
- It doesn't open on touch: what matters goes in the page, or in a Popover.
- A disabled button to explain: disabled with softDisabled — it keeps its focus and hover.
Examples
Sides
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScTooltip, ScTooltipArrow, ScTooltipPortal, ScTooltipProvider, ScTooltipTrigger,} from '@semantic-components/ui';Keyboard shortcut
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScKbd, ScTooltip, ScTooltipArrow, ScTooltipPortal, ScTooltipProvider, ScTooltipTrigger,} from '@semantic-components/ui';Disabled button
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScTooltip, ScTooltipArrow, ScTooltipPortal, ScTooltipProvider, ScTooltipTrigger,} from '@semantic-components/ui';Controlled
import { Component, ViewEncapsulation, signal } from '@angular/core';import { ScButton, ScTooltip, ScTooltipArrow, ScTooltipPortal, ScTooltipProvider, ScTooltipTrigger,} from '@semantic-components/ui';Group
import { Component, ViewEncapsulation } from '@angular/core';import { ScButton, ScTooltip, ScTooltipArrow, ScTooltipGroup, ScTooltipPortal, ScTooltipProvider, ScTooltipTrigger,} from '@semantic-components/ui';RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { ScButton, ScTooltip, ScTooltipArrow, ScTooltipPortal, ScTooltipProvider, ScTooltipTrigger,} from '@semantic-components/ui';API reference
Each part takes class, merged over the style (cn: a later class wins).
| Part | Selector | Description |
|---|---|---|
ScTooltipProvider | div[scTooltipProvider], span[scTooltipProvider] | [(open)], side ('top', 'bottom', 'left', 'right', 'inline-start', 'inline-end'), align ('start', 'center', 'end'), offset (4), delay (600), closeDelay (0), disabled. |
ScTooltipTrigger | [scTooltipTrigger] | Your control: hover opens it after the delay, keyboard focus at once; described by the tooltip while open. |
ScTooltipPortal, ScTooltip | ng-template[…], div[scTooltip] | The content, rendered while open; the tooltip (role="tooltip"), hoverable, animated. |
ScTooltipArrow | span[scTooltipArrow] | Your arrow, on the side towards the trigger. |
ScTooltipGroup | [scTooltipGroup] | Tooltips side by side: once one has shown, the next opens at once (timeout, 400). |