- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Attachment
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Bubble
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Code Block
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input Group
- Input OTP
- Input
- Item
- Kbd
- Label
- Marker
- Menubar
- Message
- Message Scroller
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Questionnaire
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner (Toast)
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toggle
- Toggle Group
- Tooltip
- Trace
Tooltip
A popup that displays information related to an element when the element receives keyboard focus or the mouse hovers over it.
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-preview',
imports: [HlmTooltipImports, HlmButtonImports],
template: `
<button hlmTooltip="Add to library" hlmBtn variant="outline">Default</button>
`,
})
export class TooltipPreview {}Installation
ng g @spartan-ng/cli:ui tooltipnx g @spartan-ng/cli:ui tooltipUsage
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';<button hlmTooltip="Add to library" hlmBtn variant="outline">Default</button>Accessibility
Prefer using tooltips as visual labels only : Tooltips should act as supplementary visual labels for sighted mouse and keyboard users. Tooltips alone are not accessible to touch users. When touch users need to read the content, use a Popover instead.
Examples
Simple
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-simple',
imports: [HlmButtonImports, HlmTooltipImports],
template: `
<button [hlmTooltip]="'Simple tooltip'" hlmBtn variant="outline">Simple</button>
`,
})
export class TooltipSimple {}Group
Provide provideBrnTooltipGroup on a wrapping component so that once one tooltip opens, the others in the group open instantly until the skip-delay window elapses.
import { Component } from '@angular/core';
import { provideBrnTooltipGroup } from '@spartan-ng/brain/tooltip';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-group',
imports: [HlmButtonImports, HlmTooltipImports],
providers: [provideBrnTooltipGroup({ skipDelayDuration: 300 })],
template: `
<div class="flex gap-2">
<button [hlmTooltip]="'Save'" hlmBtn variant="outline">Save</button>
<button [hlmTooltip]="'Copy'" hlmBtn variant="outline">Copy</button>
<button [hlmTooltip]="'Paste'" hlmBtn variant="outline">Paste</button>
</div>
`,
})
export class TooltipGroup {}Positions
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-position',
imports: [HlmButtonImports, HlmTooltipImports],
host: {
class: 'flex flex-col space-y-2',
},
template: `
<button type="button" hlmBtn variant="outline" hlmTooltip="Tooltip content" position="top">Top</button>
<div class="flex space-x-2">
<button type="button" hlmBtn variant="outline" hlmTooltip="Tooltip content" position="left">Left</button>
<button type="button" hlmBtn variant="outline" hlmTooltip="Tooltip content" position="right">Right</button>
</div>
<button type="button" hlmBtn variant="outline" hlmTooltip="Tooltip content" position="bottom">Bottom</button>
`,
})
export class TooltipPosition {}Disabled
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-disabled',
imports: [HlmButtonImports, HlmTooltipImports],
template: `
<button [hlmTooltip]="'Simple tooltip'" [tooltipDisabled]="true" hlmBtn variant="outline">Simple</button>
`,
})
export class TooltipDisabled {}Disabled Button with Tooltip
import { Component } from '@angular/core';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-disabled-button-with-tooltip',
imports: [HlmButtonImports, HlmTooltipImports],
template: `
<div hlmTooltip="Simple tooltip">
<button hlmBtn variant="outline" disabled>Disabled Button</button>
</div>
`,
})
export class TooltipDisabledButtonWithTooltip {}Template
import { Component } from '@angular/core';
import { NgIcon, provideIcons } from '@ng-icons/core';
import { lucidePlus } from '@ng-icons/lucide';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-template',
imports: [HlmButtonImports, HlmTooltipImports, NgIcon],
providers: [provideIcons({ lucidePlus })],
template: `
<button [hlmTooltip]="tooltip" hlmBtn variant="outline">Simple</button>
<ng-template #tooltip>
<span class="flex items-center">
Add to library
<ng-icon class="ml-2 text-sm" name="lucidePlus" />
</span>
</ng-template>
`,
})
export class TooltipTemplate {}RTL
To enable RTL support in spartan-ng, see the RTL configuration guide.
import { Directionality } from '@angular/cdk/bidi';
import { Component, computed, effect, inject, untracked } from '@angular/core';
import { TranslateService, Translations } from '@spartan-ng/app/app/shared/translate.service';
import { HlmButtonImports } from '@spartan-ng/helm/button';
import { HlmTooltipImports } from '@spartan-ng/helm/tooltip';
@Component({
selector: 'spartan-tooltip-rtl-preview',
imports: [HlmButtonImports, HlmTooltipImports],
providers: [Directionality],
host: {
class: 'flex w-full flex-wrap items-center justify-center gap-3',
'[dir]': '_dir()',
},
template: `
<button [hlmTooltip]="_t()['save']" position="top" hlmBtn variant="outline">{{ _t()['top'] }}</button>
<button [hlmTooltip]="_t()['save']" position="bottom" hlmBtn variant="outline">{{ _t()['bottom'] }}</button>
<button [hlmTooltip]="_t()['save']" position="left" hlmBtn variant="outline">{{ _t()['left'] }}</button>
<button [hlmTooltip]="_t()['save']" position="right" hlmBtn variant="outline">{{ _t()['right'] }}</button>
`,
})
export class TooltipRtlPreview {
private readonly _directionality = inject(Directionality);
private readonly _language = inject(TranslateService).language;
private readonly _translations: Translations = {
en: {
dir: 'ltr',
values: { save: 'Save your changes', top: 'Top', bottom: 'Bottom', left: 'Left', right: 'Right' },
},
ar: {
dir: 'rtl',
values: { save: 'احفظ تغييراتك', top: 'أعلى', bottom: 'أسفل', left: 'يسار', right: 'يمين' },
},
he: {
dir: 'rtl',
values: { save: 'שמור את השינויים שלך', top: 'למעלה', bottom: 'למטה', left: 'שמאל', right: 'ימין' },
},
};
private readonly _translation = computed(() => this._translations[this._language()]);
protected readonly _t = computed(() => this._translation().values);
protected readonly _dir = computed(() => this._translation().dir);
constructor() {
effect(() => {
const dir = this._dir();
untracked(() => this._directionality.valueSignal.set(dir));
});
}
}Brain API
BrnTooltipContent
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| id | string | `brn-tooltip-${++uniqueId}` | - |
BrnTooltipStringTemplateOutlet
Selector: [brnTooltipStringTemplateOutlet]
ExportAs: brnTooltipStringTemplateOutlet
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| brnTooltipStringTemplateOutletContext | BrnTemplateOutletContext | undefined | undefined | - |
| brnTooltipStringTemplateOutlet* (required) | T | TemplateRef<void> | - | - |
BrnTooltip
Selector: [brnTooltip]
ExportAs: brnTooltip
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| tooltipDisabled | boolean | false | - |
| position | BrnTooltipPosition | this._config.position ?? 'top' | - |
| brnTooltip | BrnTooltipType | null | - |
| showDelay | number | this._config.showDelay | - |
| hideDelay | number | this._config.hideDelay | - |
| sideOffset | number | this._config.sideOffset ?? 8 | - |
Outputs
| Prop | Type | Default | Description |
|---|---|---|---|
| show | void | - | - |
| hide | void | - | - |
Helm API
HlmTooltip
Selector: [hlmTooltip]
ExportAs: hlmTooltip
Inputs
| Prop | Type | Default | Description |
|---|---|---|---|
| hlmTooltip | BrnTooltipType | null | - |
| position | BrnTooltipPosition | this._config.position ?? 'top' | - |
| hideDelay | number | this._config.hideDelay | - |
| showDelay | number | this._config.showDelay | - |
| sideOffset | number | this._config.sideOffset ?? 8 | - |
| tooltipDisabled | boolean | false | - |
On This Page