General
Tooltip
Usage#
import { WdsTooltipComponent } from '@wds/angular/tooltip';trigger slot and the text in the default slot. The trigger must be focusable, so keyboard users can open the tooltip too.
Examples#
Default#
import { Component } from '@angular/core';
import { WdsTooltipComponent } from '@wds/angular/tooltip';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-tooltip-default-demo',
imports: [WdsTooltipComponent, WdsButtonComponent],
template: `
<wds-tooltip>
<wds-button slot="trigger" variant="outline">Hover</wds-button>
Add to library
</wds-tooltip>
`,
})
export class TooltipDefaultDemo {}Side#
side places the tooltip top (default), right, bottom or left of the trigger, and align along it (start, center, end). Without enough space the tooltip flips to the other side.
import { Component } from '@angular/core';
import { WdsTooltipComponent } from '@wds/angular/tooltip';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-tooltip-side-demo',
imports: [WdsTooltipComponent, WdsButtonComponent],
template: `
<div class="flex flex-wrap gap-2">
<wds-tooltip side="left">
<wds-button slot="trigger" variant="outline">Left</wds-button>
Add to library
</wds-tooltip>
<wds-tooltip side="top">
<wds-button slot="trigger" variant="outline">Top</wds-button>
Add to library
</wds-tooltip>
<wds-tooltip side="bottom">
<wds-button slot="trigger" variant="outline">Bottom</wds-button>
Add to library
</wds-tooltip>
<wds-tooltip side="right">
<wds-button slot="trigger" variant="outline">Right</wds-button>
Add to library
</wds-tooltip>
</div>
`,
})
export class TooltipSideDemo {}Toolbar#
label and show it in a tooltip. When the tooltip only repeats the name, it is not added as a description. Once one tooltip is open, moving to the next button opens its tooltip at once, without the delay.
import { Component } from '@angular/core';
import { WdsButtonGroupComponent } from '@wds/angular/button-group';
import { WdsTooltipComponent } from '@wds/angular/tooltip';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-tooltip-toolbar-demo',
imports: [WdsButtonGroupComponent, WdsTooltipComponent, WdsButtonComponent],
template: `
<wds-button-group aria-label="Text formatting">
<wds-tooltip>
<wds-button slot="trigger" variant="outline" size="icon" label="Bold">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8" /></svg>
</wds-button>
Bold
</wds-tooltip>
<wds-tooltip>
<wds-button slot="trigger" variant="outline" size="icon" label="Italic">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="19" x2="10" y1="4" y2="4" /><line x1="14" x2="5" y1="20" y2="20" /><line x1="15" x2="9" y1="4" y2="20" /></svg>
</wds-button>
Italic
</wds-tooltip>
<wds-tooltip>
<wds-button slot="trigger" variant="outline" size="icon" label="Underline">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 4v6a6 6 0 0 0 12 0V4" /><line x1="4" x2="20" y1="20" y2="20" /></svg>
</wds-button>
Underline
</wds-tooltip>
</wds-button-group>
`,
})
export class TooltipToolbarDemo {}Keyboard shortcut#
wds-kbd in a tooltip gets colors that fit the dark bubble. Give the button aria-keyshortcuts as well, so screen readers announce the shortcut.
import { Component } from '@angular/core';
import { WdsTooltipComponent } from '@wds/angular/tooltip';
import { WdsButtonComponent } from '@wds/angular/button';
import { WdsKbdComponent, WdsKbdGroupComponent } from '@wds/angular/kbd';
@Component({
selector: 'app-tooltip-keyboard-shortcut-demo',
imports: [WdsTooltipComponent, WdsButtonComponent, WdsKbdGroupComponent, WdsKbdComponent],
template: `
<wds-tooltip>
<wds-button slot="trigger" variant="outline" size="icon" label="Save" aria-keyshortcuts="Control+S">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z" /><path d="M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7" /><path d="M7 3v4a1 1 0 0 0 1 1h7" /></svg>
</wds-button>
Save
<wds-kbd-group><wds-kbd>Ctrl</wds-kbd><wds-kbd>S</wds-kbd></wds-kbd-group>
</wds-tooltip>
`,
})
export class TooltipKeyboardShortcutDemo {}Description#
aria-description): screen readers read "Notifications, button, 3 unread notifications".
import { Component } from '@angular/core';
import { WdsTooltipComponent } from '@wds/angular/tooltip';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-tooltip-description-demo',
imports: [WdsTooltipComponent, WdsButtonComponent],
template: `
<wds-tooltip side="bottom">
<wds-button slot="trigger" variant="outline" size="icon" label="Notifications" class="relative">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10.268 21a2 2 0 0 0 3.464 0" /><path d="M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326" /></svg>
</wds-button>
3 unread notifications
</wds-tooltip>
`,
})
export class TooltipDescriptionDemo {}Rich content#
--wds-tooltip-max-width, default 20rem). Keep it short and without links or buttons: the bubble cannot be focused. For interactive content use Popover.
import { Component } from '@angular/core';
import { WdsTooltipComponent } from '@wds/angular/tooltip';
import { WdsButtonComponent } from '@wds/angular/button';
import { WdsBadgeComponent } from '@wds/angular/badge';
@Component({
selector: 'app-tooltip-rich-content-demo',
imports: [WdsTooltipComponent, WdsButtonComponent, WdsBadgeComponent],
template: `
<wds-tooltip side="right">
<wds-button slot="trigger" variant="outline">
Version history
<wds-badge variant="secondary">Pro</wds-badge>
</wds-button>
<div class="flex max-w-56 flex-col gap-1">
<span class="font-medium">Pro feature</span>
<span class="opacity-80">Version history keeps every change for 90 days. It is part of the Pro plan.</span>
</div>
</wds-tooltip>
`,
})
export class TooltipRichContentDemo {}Disabled button#
tabindex="0" and make that the trigger. The tooltip can then explain why the action is not available.
import { Component } from '@angular/core';
import { WdsTooltipComponent } from '@wds/angular/tooltip';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-tooltip-disabled-demo',
imports: [WdsTooltipComponent, WdsButtonComponent],
template: `
<wds-tooltip>
<span slot="trigger" tabindex="0" class="inline-flex rounded-md">
<wds-button disabled>Publish</wds-button>
</span>
Only editors can publish
</wds-tooltip>
`,
})
export class TooltipDisabledDemo {}Delay and arrow#
delay milliseconds (default 200), so tooltips do not flash while the pointer crosses the page. Keyboard focus opens it at once. delay="0" opens it on hover at once, hide-arrow removes the arrow.
import { Component } from '@angular/core';
import { WdsTooltipComponent } from '@wds/angular/tooltip';
import { WdsButtonComponent } from '@wds/angular/button';
@Component({
selector: 'app-tooltip-delay-demo',
imports: [WdsTooltipComponent, WdsButtonComponent],
template: `
<div class="flex flex-wrap gap-2">
<wds-tooltip>
<wds-button slot="trigger" variant="outline">Default</wds-button>
Opens after 200 ms
</wds-tooltip>
<wds-tooltip delay="0">
<wds-button slot="trigger" variant="outline">No delay</wds-button>
Opens at once
</wds-tooltip>
<wds-tooltip hide-arrow>
<wds-button slot="trigger" variant="outline">No arrow</wds-button>
Without the arrow
</wds-tooltip>
</div>
`,
})
export class TooltipDelayDemo {}API References#
wds-tooltip#
aria-description). When it only repeats the trigger's
name (e.g. an icon button with label="Bold" and the tooltip "Bold"), it is not added, so screen readers
do not read the name twice. A tooltip holds plain text: no links or buttons, use wds-popover for those.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
| open | boolean | false | show() and hide(). |
| side | WdsTooltipSide | 'top' | |
| align | WdsTooltipAlign | 'center' | |
| offset | number | 8 | |
| delay | number | 200 | |
| disabled | boolean | false | |
| hide-arrow.hideArrow | boolean | false |
Events
| Event | Description |
|---|---|
| wds-open-changeCustomEvent<WdsTooltipOpenChangeDetail> |
Methods
| Method | Description |
|---|---|
| show() | |
| hide() |
Slots
| Slot | Description |
|---|---|
| trigger | wds-button). It must be focusable: wrap a disabled button in an element with tabindex="0". |
| (default) | wds-kbd gets colors that fit the dark bubble. |
CSS parts (::part)
| Part | Description |
|---|---|
| content | |
| arrow |
CSS custom properties
| Property | Description |
|---|---|
| --wds-tooltip-bg | --wds-foreground). |
| --wds-tooltip-fg | --wds-background). |
| --wds-tooltip-max-width |
Accessibility#
Screen reader#
role="tooltip". Its text is set as aria-description on the trigger (wds-button forwards it to the native button), so screen readers read it after the name and the role.
label, aria-label or text), no description is added, so the name is not read twice. Name icon buttons with label: a tooltip is not a name.
wds-popover for them.
Keyboard support#
| Key | Function |
|---|---|