@fundamental-ngx/core 0.66.1-rc.8 → 0.66.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/fesm2022/fundamental-ngx-core-card.mjs +55 -3
- package/fesm2022/fundamental-ngx-core-card.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-combobox.mjs +5 -2
- package/fesm2022/fundamental-ngx-core-combobox.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-date-picker.mjs +1 -1
- package/fesm2022/fundamental-ngx-core-date-picker.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-datetime-picker.mjs +1 -1
- package/fesm2022/fundamental-ngx-core-datetime-picker.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-datetime.mjs +4 -2
- package/fesm2022/fundamental-ngx-core-datetime.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-dialog.mjs +71 -19
- package/fesm2022/fundamental-ngx-core-dialog.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-form.mjs +932 -69
- package/fesm2022/fundamental-ngx-core-form.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-input-group.mjs +2 -2
- package/fesm2022/fundamental-ngx-core-input-group.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-menu.mjs +1 -1
- package/fesm2022/fundamental-ngx-core-menu.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-message-box.mjs +2 -10
- package/fesm2022/fundamental-ngx-core-message-box.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-message-strip.mjs +2 -3
- package/fesm2022/fundamental-ngx-core-message-strip.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-multi-combobox.mjs +3 -3
- package/fesm2022/fundamental-ngx-core-multi-combobox.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-multi-input.mjs +2 -2
- package/fesm2022/fundamental-ngx-core-multi-input.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-pagination.mjs +1 -1
- package/fesm2022/fundamental-ngx-core-pagination.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-popover.mjs +22 -6
- package/fesm2022/fundamental-ngx-core-popover.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-product-switch.mjs +2 -2
- package/fesm2022/fundamental-ngx-core-product-switch.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-radio.mjs +47 -2
- package/fesm2022/fundamental-ngx-core-radio.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-select.mjs +1 -1
- package/fesm2022/fundamental-ngx-core-select.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-settings.mjs +2 -2
- package/fesm2022/fundamental-ngx-core-settings.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-shellbar.mjs +732 -113
- package/fesm2022/fundamental-ngx-core-shellbar.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-text.mjs +2 -2
- package/fesm2022/fundamental-ngx-core-text.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-time-picker.mjs +3 -4
- package/fesm2022/fundamental-ngx-core-time-picker.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-token.mjs +14 -18
- package/fesm2022/fundamental-ngx-core-token.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-tooltip.mjs +903 -0
- package/fesm2022/fundamental-ngx-core-tooltip.mjs.map +1 -0
- package/fesm2022/fundamental-ngx-core-upload-collection.mjs +1 -1
- package/fesm2022/fundamental-ngx-core-upload-collection.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core-user-menu.mjs +21 -8
- package/fesm2022/fundamental-ngx-core-user-menu.mjs.map +1 -1
- package/fesm2022/fundamental-ngx-core.mjs +1 -0
- package/fesm2022/fundamental-ngx-core.mjs.map +1 -1
- package/package.json +7 -3
- package/schematics/package.json +1 -1
- package/types/fundamental-ngx-core-card.d.ts +34 -1
- package/types/fundamental-ngx-core-dialog.d.ts +33 -5
- package/types/fundamental-ngx-core-form.d.ts +261 -34
- package/types/fundamental-ngx-core-popover.d.ts +6 -0
- package/types/fundamental-ngx-core-radio.d.ts +8 -0
- package/types/fundamental-ngx-core-shellbar.d.ts +259 -75
- package/types/fundamental-ngx-core-token.d.ts +2 -0
- package/types/fundamental-ngx-core-tooltip.d.ts +456 -0
- package/types/fundamental-ngx-core-user-menu.d.ts +4 -0
- package/types/fundamental-ngx-core.d.ts +1 -0
|
@@ -0,0 +1,903 @@
|
|
|
1
|
+
import { ESCAPE, ENTER } from '@angular/cdk/keycodes';
|
|
2
|
+
import { isPlatformBrowser } from '@angular/common';
|
|
3
|
+
import * as i0 from '@angular/core';
|
|
4
|
+
import { inject, DOCUMENT, PLATFORM_ID, DestroyRef, Service, InjectionToken, input, booleanAttribute, ElementRef, Renderer2, ApplicationRef, computed, TemplateRef, effect, untracked, afterRenderEffect, RendererStyleFlags2, Directive } from '@angular/core';
|
|
5
|
+
import { KeyUtil, RtlService } from '@fundamental-ngx/cdk/utils';
|
|
6
|
+
import { InputModalityDetector } from '@angular/cdk/a11y';
|
|
7
|
+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
8
|
+
import { PopoverService, buildPopoverConfig } from '@fundamental-ngx/core/popover';
|
|
9
|
+
import { PopoverPosition } from '@fundamental-ngx/core/shared';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Application-wide service that decides when tooltips are shown and hidden.
|
|
13
|
+
*
|
|
14
|
+
* - Guarantees that at most one tooltip is visible at any time.
|
|
15
|
+
* - Owns the show, hide and sequence delay timers, so timing is consistent across all tooltips.
|
|
16
|
+
* - Listens globally for `Escape`, window blur and tab switching to dismiss the open tooltip.
|
|
17
|
+
*
|
|
18
|
+
* Tooltips request showing and hiding through `show()` and `hide()`; they never open their overlay on their own.
|
|
19
|
+
*/
|
|
20
|
+
class TooltipCoordinator {
|
|
21
|
+
/**
|
|
22
|
+
* @hidden
|
|
23
|
+
* Registers the window `blur`, window `focus` and `visibilitychange` listeners for the whole application
|
|
24
|
+
* (browser only) and removes them when the root injector is destroyed. These events are rare, so they
|
|
25
|
+
* are always listened to. The frequent `keydown` event is only listened to while a tooltip needs it,
|
|
26
|
+
* see `_syncKeydownListener()`.
|
|
27
|
+
*/
|
|
28
|
+
constructor() {
|
|
29
|
+
/**
|
|
30
|
+
* @hidden
|
|
31
|
+
* Tooltip that was opened last. Its overlay may already be closed (e.g. by an outside click),
|
|
32
|
+
* so check `isOpen()` before treating it as visible.
|
|
33
|
+
*/
|
|
34
|
+
this._active = null;
|
|
35
|
+
/** @hidden Tooltip waiting for its show delay to elapse. Only one tooltip can be pending at a time. */
|
|
36
|
+
this._pending = null;
|
|
37
|
+
/** @hidden Timer that opens the pending tooltip once its show or sequence delay elapses. */
|
|
38
|
+
this._showTimer = null;
|
|
39
|
+
/** @hidden Timer that closes the active tooltip once its hide delay elapses. */
|
|
40
|
+
this._hideTimer = null;
|
|
41
|
+
/**
|
|
42
|
+
* @hidden
|
|
43
|
+
* `true` only during the task in which the browser window or tab was activated again.
|
|
44
|
+
* Lets tooltips ignore the focus event the browser then fires on the previously focused element.
|
|
45
|
+
*/
|
|
46
|
+
this._windowRefocused = false;
|
|
47
|
+
/** @hidden Whether the `Escape` listener is currently attached to the document. */
|
|
48
|
+
this._listeningToKeydown = false;
|
|
49
|
+
/** @hidden Document the global listeners are attached to. */
|
|
50
|
+
this._document = inject(DOCUMENT);
|
|
51
|
+
/** @hidden Browser window, or `null` on the server, where no global listeners are attached. */
|
|
52
|
+
this._window = isPlatformBrowser(inject(PLATFORM_ID)) ? this._document.defaultView : null;
|
|
53
|
+
/** @hidden Stable reference to the `Escape` handler, so the same listener can be added and removed. */
|
|
54
|
+
this._keydownListener = this._onKeydown.bind(this);
|
|
55
|
+
const win = this._window;
|
|
56
|
+
if (!win) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const onWindowBlur = () => this._dismiss();
|
|
60
|
+
const onWindowFocus = () => this._onWindowFocus();
|
|
61
|
+
const onVisibilityChange = () => {
|
|
62
|
+
if (this._document.visibilityState === 'hidden') {
|
|
63
|
+
this._dismiss();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
this._document.addEventListener('visibilitychange', onVisibilityChange);
|
|
67
|
+
win.addEventListener('blur', onWindowBlur);
|
|
68
|
+
win.addEventListener('focus', onWindowFocus);
|
|
69
|
+
inject(DestroyRef).onDestroy(() => {
|
|
70
|
+
this._clearShowTimer();
|
|
71
|
+
this._clearHideTimer();
|
|
72
|
+
this._document.removeEventListener('keydown', this._keydownListener, true);
|
|
73
|
+
this._document.removeEventListener('visibilitychange', onVisibilityChange);
|
|
74
|
+
win.removeEventListener('blur', onWindowBlur);
|
|
75
|
+
win.removeEventListener('focus', onWindowFocus);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Requests to show a tooltip.
|
|
80
|
+
*
|
|
81
|
+
* - If the tooltip is already visible, it stays open and a scheduled hide is cancelled.
|
|
82
|
+
* - If the tooltip is already waiting for its delay, the running timer is kept.
|
|
83
|
+
* - If another tooltip is visible, that one closes immediately and this one opens after
|
|
84
|
+
* `sequenceDelay` (or `delay`, if shorter), so moving between elements feels faster.
|
|
85
|
+
* - A `delay` of `0` or less opens the tooltip immediately (keyboard shortcut, long-press, `show()`).
|
|
86
|
+
*
|
|
87
|
+
* @param tooltip Tooltip to show.
|
|
88
|
+
* @param delay Delay in ms before showing when no other tooltip is visible.
|
|
89
|
+
* @param sequenceDelay Delay in ms before showing when another tooltip is visible.
|
|
90
|
+
*/
|
|
91
|
+
show(tooltip, delay, sequenceDelay = delay) {
|
|
92
|
+
if (this._active === tooltip && tooltip.isOpen()) {
|
|
93
|
+
this._clearHideTimer();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (this._pending === tooltip && delay > 0) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
this._clearShowTimer();
|
|
100
|
+
if (this._active?.isOpen()) {
|
|
101
|
+
this._hideActive();
|
|
102
|
+
delay = Math.min(delay, sequenceDelay);
|
|
103
|
+
}
|
|
104
|
+
if (delay <= 0) {
|
|
105
|
+
this._open(tooltip);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
this._pending = tooltip;
|
|
109
|
+
this._syncKeydownListener();
|
|
110
|
+
this._showTimer = setTimeout(() => {
|
|
111
|
+
this._showTimer = null;
|
|
112
|
+
this._pending = null;
|
|
113
|
+
this._open(tooltip);
|
|
114
|
+
}, delay);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Requests to hide a tooltip.
|
|
118
|
+
*
|
|
119
|
+
* - Cancels the tooltip's pending show, so it does not appear after the pointer or focus has already left.
|
|
120
|
+
* - If the tooltip is visible, closes it after `delay`, or immediately when `delay` is `0` or less.
|
|
121
|
+
* - Does nothing for a tooltip that is neither pending nor visible.
|
|
122
|
+
*
|
|
123
|
+
* @param tooltip Tooltip to hide.
|
|
124
|
+
* @param delay Delay in ms before hiding.
|
|
125
|
+
*/
|
|
126
|
+
hide(tooltip, delay) {
|
|
127
|
+
if (this._pending === tooltip) {
|
|
128
|
+
this._clearShowTimer();
|
|
129
|
+
}
|
|
130
|
+
if (this._active !== tooltip) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this._clearHideTimer();
|
|
134
|
+
if (delay <= 0) {
|
|
135
|
+
this._hideActive();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this._hideTimer = setTimeout(() => {
|
|
139
|
+
this._hideTimer = null;
|
|
140
|
+
this._hideActive();
|
|
141
|
+
}, delay);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Cancels a scheduled hide and keeps the tooltip open.
|
|
145
|
+
* Used when the pointer moves from the host onto the tooltip, so its text can be read or selected.
|
|
146
|
+
*
|
|
147
|
+
* @param tooltip Tooltip to keep open.
|
|
148
|
+
*/
|
|
149
|
+
cancelHide(tooltip) {
|
|
150
|
+
if (this._active === tooltip) {
|
|
151
|
+
this._clearHideTimer();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Removes every reference to the tooltip: cancels its pending show and scheduled hide and
|
|
156
|
+
* forgets it as the active tooltip. The overlay is not touched, because it is disposed together
|
|
157
|
+
* with the tooltip. Must be called when the tooltip is destroyed.
|
|
158
|
+
*
|
|
159
|
+
* @param tooltip Tooltip being destroyed.
|
|
160
|
+
*/
|
|
161
|
+
unregister(tooltip) {
|
|
162
|
+
if (this._pending === tooltip) {
|
|
163
|
+
this._clearShowTimer();
|
|
164
|
+
}
|
|
165
|
+
if (this._active === tooltip) {
|
|
166
|
+
this._clearHideTimer();
|
|
167
|
+
this._active = null;
|
|
168
|
+
this._syncKeydownListener();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Whether the current focus event was caused by the browser restoring focus after the window
|
|
173
|
+
* or tab was activated again. Tooltips skip showing on such focus events, because the user did
|
|
174
|
+
* not interact with the page.
|
|
175
|
+
*/
|
|
176
|
+
isWindowRefocus() {
|
|
177
|
+
return this._windowRefocused;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* @hidden
|
|
181
|
+
* Makes the tooltip the active one and opens it.
|
|
182
|
+
* Closes any other visible tooltip first to keep the single-tooltip guarantee.
|
|
183
|
+
*/
|
|
184
|
+
_open(tooltip) {
|
|
185
|
+
if (this._active !== tooltip) {
|
|
186
|
+
this._hideActive();
|
|
187
|
+
}
|
|
188
|
+
this._active = tooltip;
|
|
189
|
+
this._syncKeydownListener();
|
|
190
|
+
tooltip.open();
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* @hidden
|
|
194
|
+
* Closes the active tooltip immediately and cancels its scheduled hide.
|
|
195
|
+
* `_active` is reset before `close()` runs, so re-entrant calls see a consistent state.
|
|
196
|
+
*/
|
|
197
|
+
_hideActive() {
|
|
198
|
+
this._clearHideTimer();
|
|
199
|
+
const active = this._active;
|
|
200
|
+
this._active = null;
|
|
201
|
+
this._syncKeydownListener();
|
|
202
|
+
active?.close();
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* @hidden
|
|
206
|
+
* Global `Escape` handler. Always cancels a pending show. If a tooltip is visible, closes it and
|
|
207
|
+
* stops the event, so the first `Escape` only closes the tooltip and not, for example, the surrounding
|
|
208
|
+
* dialog. If no tooltip is visible, the event passes through untouched.
|
|
209
|
+
*/
|
|
210
|
+
_onKeydown(event) {
|
|
211
|
+
if (!KeyUtil.isKeyCode(event, ESCAPE)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
this._clearShowTimer();
|
|
215
|
+
if (this._active?.isOpen()) {
|
|
216
|
+
event.stopPropagation();
|
|
217
|
+
this._hideActive();
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* @hidden
|
|
222
|
+
* Closes the active tooltip and cancels a pending show.
|
|
223
|
+
* Called when the window loses focus or the page becomes hidden (tab switch, minimised window).
|
|
224
|
+
*/
|
|
225
|
+
_dismiss() {
|
|
226
|
+
this._clearShowTimer();
|
|
227
|
+
this._hideActive();
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* @hidden
|
|
231
|
+
* Marks the current task as a window re-activation (see `isWindowRefocus()`).
|
|
232
|
+
* The flag is reset in the next task.
|
|
233
|
+
*/
|
|
234
|
+
_onWindowFocus() {
|
|
235
|
+
// The element focus event follows the window focus event within the same task.
|
|
236
|
+
this._windowRefocused = true;
|
|
237
|
+
setTimeout(() => (this._windowRefocused = false));
|
|
238
|
+
}
|
|
239
|
+
/** @hidden Cancels the pending show and forgets the pending tooltip. */
|
|
240
|
+
_clearShowTimer() {
|
|
241
|
+
if (this._showTimer !== null) {
|
|
242
|
+
clearTimeout(this._showTimer);
|
|
243
|
+
this._showTimer = null;
|
|
244
|
+
}
|
|
245
|
+
this._pending = null;
|
|
246
|
+
this._syncKeydownListener();
|
|
247
|
+
}
|
|
248
|
+
/** @hidden Cancels the scheduled hide of the active tooltip. */
|
|
249
|
+
_clearHideTimer() {
|
|
250
|
+
if (this._hideTimer !== null) {
|
|
251
|
+
clearTimeout(this._hideTimer);
|
|
252
|
+
this._hideTimer = null;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* @hidden
|
|
257
|
+
* Attaches the `Escape` listener while a tooltip is open or pending and removes it otherwise,
|
|
258
|
+
* so key presses do not reach this service (or trigger change detection) when no tooltip is involved.
|
|
259
|
+
* The listener uses the capture phase, so an open tooltip consumes `Escape` before the host
|
|
260
|
+
* (e.g. a dialog) sees it.
|
|
261
|
+
*/
|
|
262
|
+
_syncKeydownListener() {
|
|
263
|
+
const needed = !!this._window && (this._active !== null || this._pending !== null);
|
|
264
|
+
if (needed === this._listeningToKeydown) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
this._listeningToKeydown = needed;
|
|
268
|
+
if (needed) {
|
|
269
|
+
this._document.addEventListener('keydown', this._keydownListener, true);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
this._document.removeEventListener('keydown', this._keydownListener, true);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: TooltipCoordinator, deps: [], target: i0.ɵɵFactoryTarget.Service }); }
|
|
276
|
+
static { this.ɵprov = i0.ɵɵngDeclareService({ minVersion: "22.0.0", version: "22.2.1", ngImport: i0, type: TooltipCoordinator }); }
|
|
277
|
+
}
|
|
278
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: TooltipCoordinator, decorators: [{
|
|
279
|
+
type: Service
|
|
280
|
+
}], ctorParameters: () => [] });
|
|
281
|
+
|
|
282
|
+
const DEFAULT_TOOLTIP_CONFIG = {
|
|
283
|
+
showDelay: 500,
|
|
284
|
+
hideDelay: 500,
|
|
285
|
+
sequenceDelay: 200
|
|
286
|
+
};
|
|
287
|
+
/**
|
|
288
|
+
* Overrides the global tooltip timing. Missing values fall back to `DEFAULT_TOOLTIP_CONFIG`.
|
|
289
|
+
* ```ts
|
|
290
|
+
* providers: [{ provide: TOOLTIP_CONFIG, useValue: { showDelay: 300 } }]
|
|
291
|
+
* ```
|
|
292
|
+
*/
|
|
293
|
+
const TOOLTIP_CONFIG = new InjectionToken('FdTooltipConfig', {
|
|
294
|
+
factory: () => ({})
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
/** Modifier class that applies the tooltip styling (dark surface, small font, max width) to the popover body. */
|
|
298
|
+
const TOOLTIP_BODY_CLASS = 'fd-popover__body--tooltip';
|
|
299
|
+
/** How long in ms a touch has to be held before it counts as a long-press. */
|
|
300
|
+
const LONG_PRESS_DURATION = 500;
|
|
301
|
+
/** Side the tooltip flips to when the preferred side does not fit into the viewport. */
|
|
302
|
+
const OPPOSITE_PLACEMENT = {
|
|
303
|
+
top: 'bottom',
|
|
304
|
+
bottom: 'top',
|
|
305
|
+
left: 'right',
|
|
306
|
+
right: 'left'
|
|
307
|
+
};
|
|
308
|
+
/** Counter used to generate unique tooltip ids. */
|
|
309
|
+
let tooltipUniqueId = 0;
|
|
310
|
+
/** Maps side and alignment to the popover `Placement` format, e.g. `top` + `start` → `top-start`. */
|
|
311
|
+
const toPlacement = (side, alignment) => alignment === 'middle' ? side : `${side}-${alignment}`;
|
|
312
|
+
/** Normalises text for comparison: collapses whitespace, trims and lowercases. */
|
|
313
|
+
const normalizeText = (value) => value.replace(/\s+/g, ' ').trim().toLowerCase();
|
|
314
|
+
/**
|
|
315
|
+
* Normalises a keyboard shortcut for comparison so the human-readable form in the tooltip text
|
|
316
|
+
* (e.g. `Ctrl+S`) and the `aria-keyshortcuts` form (e.g. `Control+S`) compare equal. Lowercases,
|
|
317
|
+
* unifies common aliases (`ctrl`→`control`, `cmd`/`command`→`meta`, `opt`/`option`→`alt`,
|
|
318
|
+
* `esc`→`escape`) and collapses `+`/`-`/whitespace separators to a single `+`.
|
|
319
|
+
*/
|
|
320
|
+
const normalizeShortcut = (value) => value
|
|
321
|
+
.toLowerCase()
|
|
322
|
+
.replace(/\bctrl\b/g, 'control')
|
|
323
|
+
.replace(/\b(cmd|command)\b/g, 'meta')
|
|
324
|
+
.replace(/\b(opt|option)\b/g, 'alt')
|
|
325
|
+
.replace(/\besc\b/g, 'escape')
|
|
326
|
+
.replace(/[\s+-]+/g, '+')
|
|
327
|
+
.replace(/^\+|\+$/g, '');
|
|
328
|
+
/**
|
|
329
|
+
* Whether `parenthetical` (the inner text of a trailing `(...)` in the tooltip text) spells out one
|
|
330
|
+
* of the shortcut chords in `shortcuts` (an `aria-keyshortcuts` value, which may list several chords
|
|
331
|
+
* separated by spaces). Comparison is tolerant of separator and casing differences.
|
|
332
|
+
*/
|
|
333
|
+
const isShortcutNotation = (parenthetical, shortcuts) => {
|
|
334
|
+
const candidate = normalizeShortcut(parenthetical);
|
|
335
|
+
return !!candidate && shortcuts.split(/\s+/).some((chord) => normalizeShortcut(chord) === candidate);
|
|
336
|
+
};
|
|
337
|
+
/**
|
|
338
|
+
* Shows a short tooltip for the host element.
|
|
339
|
+
*
|
|
340
|
+
* By default, the tooltip opens after a delay on mouse hover or keyboard focus, and immediately on touch
|
|
341
|
+
* long-press or `Ctrl+Alt+I` (Windows/Linux) / `Ctrl+Option+I` (Mac). It closes when the pointer or focus leaves, on `Escape`, when the host is
|
|
342
|
+
* activated, on outside click, and when the window loses focus. With `fdTooltipTrigger="click"` it is
|
|
343
|
+
* toggled by clicking the host instead.
|
|
344
|
+
*
|
|
345
|
+
* The overlay is rendered by `PopoverService` (positioning, flipping, arrow), while `TooltipCoordinator`
|
|
346
|
+
* decides when to show and hide, so only one tooltip is visible at a time. The host's DOM is never
|
|
347
|
+
* changed; only ARIA attributes are added.
|
|
348
|
+
*
|
|
349
|
+
* The text is assembled by the caller, e.g. `Label - Description (Shortcut)`. A template can be passed
|
|
350
|
+
* instead of text for formatted, non-interactive content.
|
|
351
|
+
*
|
|
352
|
+
* ```html
|
|
353
|
+
* <button fd-button glyph="save" aria-label="Save" fdTooltip="Save (Ctrl+S)" fdTooltipKeyShortcuts="Control+S"></button>
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
class TooltipDirective {
|
|
357
|
+
/**
|
|
358
|
+
* @hidden
|
|
359
|
+
* Wires the directive up reactively:
|
|
360
|
+
* 1. Keeps the popover configuration in sync with the inputs.
|
|
361
|
+
* 2. Keeps the overlay content in sync with `fdTooltip`.
|
|
362
|
+
* 3. Attaches the host listeners only while the tooltip is enabled; disabling it removes them and closes the tooltip.
|
|
363
|
+
* 4. After each render, updates the ARIA attributes and the hidden description element.
|
|
364
|
+
* 5. Attaches hover listeners to the overlay each time it opens, so the tooltip stays open while hovered.
|
|
365
|
+
* 6. On destroy, unregisters from the coordinator and removes everything added to the DOM.
|
|
366
|
+
*/
|
|
367
|
+
constructor() {
|
|
368
|
+
/**
|
|
369
|
+
* Content of the tooltip: text already assembled by the caller, e.g. `Save (Ctrl+S)`, or a template
|
|
370
|
+
* for formatted text. Templates must not contain interactive elements; use a popover for those.
|
|
371
|
+
* An empty or whitespace-only text disables the tooltip, the same as `fdTooltipDisabled`.
|
|
372
|
+
*/
|
|
373
|
+
this.fdTooltip = input('', /* @ts-ignore */
|
|
374
|
+
...(ngDevMode ? [{ debugName: "fdTooltip" }] : /* istanbul ignore next */ []));
|
|
375
|
+
/**
|
|
376
|
+
* Side of the host element the tooltip is shown on.
|
|
377
|
+
* When there is not enough room, the tooltip flips to the opposite side automatically.
|
|
378
|
+
*/
|
|
379
|
+
this.fdTooltipPlacement = input('bottom', /* @ts-ignore */
|
|
380
|
+
...(ngDevMode ? [{ debugName: "fdTooltipPlacement" }] : /* istanbul ignore next */ []));
|
|
381
|
+
/** Alignment along the chosen side: `start`/`end` align with the host's edge, `middle` centres the tooltip. */
|
|
382
|
+
this.fdTooltipAlignment = input('middle', /* @ts-ignore */
|
|
383
|
+
...(ngDevMode ? [{ debugName: "fdTooltipAlignment" }] : /* istanbul ignore next */ []));
|
|
384
|
+
/**
|
|
385
|
+
* How the tooltip is opened:
|
|
386
|
+
* - `hover` (default): after a delay on mouse hover or keyboard focus, immediately on touch long-press.
|
|
387
|
+
* - `click`: toggled immediately by clicking, tapping or activating the host with the keyboard. It stays
|
|
388
|
+
* open until it is toggled again, `Escape` is pressed, the user clicks elsewhere or focus moves away.
|
|
389
|
+
* Use it only on hosts without their own action, e.g. an information button next to a label.
|
|
390
|
+
*
|
|
391
|
+
* `Ctrl+Alt+I` (Windows/Linux) / `Ctrl+Option+I` (Mac) toggles the tooltip in both modes.
|
|
392
|
+
*/
|
|
393
|
+
this.fdTooltipTrigger = input('hover', /* @ts-ignore */
|
|
394
|
+
...(ngDevMode ? [{ debugName: "fdTooltipTrigger" }] : /* istanbul ignore next */ []));
|
|
395
|
+
/**
|
|
396
|
+
* Disables the tooltip. A disabled tooltip never shows and adds no ARIA attributes or event listeners,
|
|
397
|
+
* so the host behaves exactly as without the directive. Use it, for example, to enable the tooltip
|
|
398
|
+
* only while the host text is truncated.
|
|
399
|
+
*/
|
|
400
|
+
this.fdTooltipDisabled = input(false, { ...(ngDevMode ? { debugName: "fdTooltipDisabled" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
401
|
+
/**
|
|
402
|
+
* Delay in ms before the tooltip shows on hover or keyboard focus.
|
|
403
|
+
* When `null`, `TOOLTIP_CONFIG.showDelay` (500 ms by default) is used.
|
|
404
|
+
*/
|
|
405
|
+
this.fdTooltipShowDelay = input(null, /* @ts-ignore */
|
|
406
|
+
...(ngDevMode ? [{ debugName: "fdTooltipShowDelay" }] : /* istanbul ignore next */ []));
|
|
407
|
+
/**
|
|
408
|
+
* Delay in ms before the tooltip hides after the pointer or focus leaves the host or the tooltip.
|
|
409
|
+
* When `null`, `TOOLTIP_CONFIG.hideDelay` (500 ms by default) is used.
|
|
410
|
+
*/
|
|
411
|
+
this.fdTooltipHideDelay = input(null, /* @ts-ignore */
|
|
412
|
+
...(ngDevMode ? [{ debugName: "fdTooltipHideDelay" }] : /* istanbul ignore next */ []));
|
|
413
|
+
/**
|
|
414
|
+
* Keyboard shortcut of the host action in `aria-keyshortcuts` format, e.g. `Control+S`.
|
|
415
|
+
* It is set as `aria-keyshortcuts` on the host, and for text content a trailing parenthesised
|
|
416
|
+
* shortcut that matches this value, e.g. ` (Ctrl+S)`, is removed from the screen reader
|
|
417
|
+
* description so it is not announced twice. A trailing parenthetical that is not the shortcut
|
|
418
|
+
* (e.g. ` (3 copies)`) is left intact.
|
|
419
|
+
*/
|
|
420
|
+
this.fdTooltipKeyShortcuts = input(null, /* @ts-ignore */
|
|
421
|
+
...(ngDevMode ? [{ debugName: "fdTooltipKeyShortcuts" }] : /* istanbul ignore next */ []));
|
|
422
|
+
/**
|
|
423
|
+
* Additional CSS class(es) for the tooltip body, e.g. to customise its styling.
|
|
424
|
+
* The tooltip is rendered in an overlay, so the styles must not be encapsulated in a component.
|
|
425
|
+
*/
|
|
426
|
+
this.fdTooltipBodyClass = input(null, /* @ts-ignore */
|
|
427
|
+
...(ngDevMode ? [{ debugName: "fdTooltipBodyClass" }] : /* istanbul ignore next */ []));
|
|
428
|
+
/**
|
|
429
|
+
* Unique id of the rendered tooltip container (`role="tooltip"`).
|
|
430
|
+
* The hidden screen reader description uses `<tooltipId>-description`.
|
|
431
|
+
*/
|
|
432
|
+
this.tooltipId = `fd-tooltip-${++tooltipUniqueId}`;
|
|
433
|
+
/** @hidden Host element reference, passed to `PopoverService` as the overlay origin. */
|
|
434
|
+
this._elementRef = inject(ElementRef);
|
|
435
|
+
/** @hidden Host element, used for event listeners and ARIA attributes. */
|
|
436
|
+
this._host = this._elementRef.nativeElement;
|
|
437
|
+
/** @hidden Per-instance popover service that renders, positions and disposes the tooltip overlay. */
|
|
438
|
+
this._popoverService = inject(PopoverService);
|
|
439
|
+
/** @hidden Application-wide service that decides when this tooltip shows or hides. */
|
|
440
|
+
this._coordinator = inject(TooltipCoordinator);
|
|
441
|
+
/**
|
|
442
|
+
* @hidden
|
|
443
|
+
* What the coordinator uses to open and close this tooltip's overlay without delay.
|
|
444
|
+
* Kept in a private object so these delay-free operations are not part of the directive's public API.
|
|
445
|
+
*/
|
|
446
|
+
this._handle = {
|
|
447
|
+
isOpen: () => this._popoverService.isOpen(),
|
|
448
|
+
open: () => this._popoverService.open(),
|
|
449
|
+
close: () => {
|
|
450
|
+
this._removeBodyListeners();
|
|
451
|
+
if (this._popoverService.isOpen()) {
|
|
452
|
+
this._popoverService.close(false);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* @hidden
|
|
458
|
+
* Tracks whether the last user input was keyboard, mouse or touch,
|
|
459
|
+
* so focus only shows the tooltip when it came from the keyboard.
|
|
460
|
+
*/
|
|
461
|
+
this._inputModality = inject(InputModalityDetector);
|
|
462
|
+
/** @hidden Text direction, used to mirror left/right placements in RTL. */
|
|
463
|
+
this._rtlService = inject(RtlService, { optional: true });
|
|
464
|
+
/** @hidden Used for all DOM writes and event listeners. */
|
|
465
|
+
this._renderer = inject(Renderer2);
|
|
466
|
+
/** @hidden Used to append and look up the hidden description element. */
|
|
467
|
+
this._document = inject(DOCUMENT);
|
|
468
|
+
/** @hidden Keeps the template rendered into the hidden description element up to date. */
|
|
469
|
+
this._appRef = inject(ApplicationRef);
|
|
470
|
+
/** @hidden Effective timing: the defaults overridden by the provided `TOOLTIP_CONFIG`. */
|
|
471
|
+
this._config = { ...DEFAULT_TOOLTIP_CONFIG, ...inject(TOOLTIP_CONFIG) };
|
|
472
|
+
/** @hidden Id of the hidden description element referenced by the host's `aria-describedby`. */
|
|
473
|
+
this._descriptionId = `${this.tooltipId}-description`;
|
|
474
|
+
/** @hidden Text content, or an empty string when a template is used. */
|
|
475
|
+
this._text = computed(() => {
|
|
476
|
+
const content = this.fdTooltip();
|
|
477
|
+
return typeof content === 'string' ? content.trim() : '';
|
|
478
|
+
}, /* @ts-ignore */
|
|
479
|
+
...(ngDevMode ? [{ debugName: "_text" }] : /* istanbul ignore next */ []));
|
|
480
|
+
/** @hidden Template content, or `null` when text is used. */
|
|
481
|
+
this._template = computed(() => {
|
|
482
|
+
const content = this.fdTooltip();
|
|
483
|
+
return content instanceof TemplateRef ? content : null;
|
|
484
|
+
}, /* @ts-ignore */
|
|
485
|
+
...(ngDevMode ? [{ debugName: "_template" }] : /* istanbul ignore next */ []));
|
|
486
|
+
/**
|
|
487
|
+
* @hidden
|
|
488
|
+
* Whether the tooltip is active: not disabled and has a template or non-empty text.
|
|
489
|
+
* Drives the host listeners, the ARIA attributes and the popover `disabled` state.
|
|
490
|
+
*/
|
|
491
|
+
this._enabled = computed(() => !this.fdTooltipDisabled() && (!!this._text() || !!this._template()), /* @ts-ignore */
|
|
492
|
+
...(ngDevMode ? [{ debugName: "_enabled" }] : /* istanbul ignore next */ []));
|
|
493
|
+
/**
|
|
494
|
+
* @hidden
|
|
495
|
+
* Text announced by screen readers for text content. Equals the tooltip text, except that the trailing
|
|
496
|
+
* `(shortcut)` is removed when `fdTooltipKeyShortcuts` is set, because the shortcut is announced via
|
|
497
|
+
* `aria-keyshortcuts`. Template content is announced as rendered.
|
|
498
|
+
*/
|
|
499
|
+
this._description = computed(() => {
|
|
500
|
+
const text = this._text();
|
|
501
|
+
const shortcuts = this.fdTooltipKeyShortcuts();
|
|
502
|
+
if (!shortcuts) {
|
|
503
|
+
return text;
|
|
504
|
+
}
|
|
505
|
+
// Only strip the trailing parenthetical when it actually spells out the configured shortcut
|
|
506
|
+
// (e.g. "Save (Ctrl+S)" with fdTooltipKeyShortcuts="Control+S"), so the shortcut is not
|
|
507
|
+
// announced twice. A non-shortcut qualifier like "Print (3 copies)" is left intact.
|
|
508
|
+
const match = text.match(/\s*\(([^()]*)\)$/);
|
|
509
|
+
return match && isShortcutNotation(match[1], shortcuts) ? text.slice(0, match.index).trimEnd() : text;
|
|
510
|
+
}, /* @ts-ignore */
|
|
511
|
+
...(ngDevMode ? [{ debugName: "_description" }] : /* istanbul ignore next */ []));
|
|
512
|
+
/**
|
|
513
|
+
* @hidden
|
|
514
|
+
* Overlay positions passed to the popover: the preferred placement first and the opposite side second,
|
|
515
|
+
* so the overlay flips to the opposite side when the preferred one does not fit.
|
|
516
|
+
*/
|
|
517
|
+
this._positions = computed(() => {
|
|
518
|
+
const direction = this._rtlService?.rtl() ? 'rtl' : 'ltr';
|
|
519
|
+
const placement = this.fdTooltipPlacement();
|
|
520
|
+
const alignment = this.fdTooltipAlignment();
|
|
521
|
+
return [placement, OPPOSITE_PLACEMENT[placement]].map((side) => PopoverPosition.getCdkPlacement(toPlacement(side, alignment), direction));
|
|
522
|
+
}, /* @ts-ignore */
|
|
523
|
+
...(ngDevMode ? [{ debugName: "_positions" }] : /* istanbul ignore next */ []));
|
|
524
|
+
/**
|
|
525
|
+
* @hidden
|
|
526
|
+
* Popover configuration for the tooltip overlay. Triggers are empty because this directive and the
|
|
527
|
+
* coordinator handle all events and timing; the popover only renders. `Escape` is handled by the
|
|
528
|
+
* coordinator, outside clicks by the popover.
|
|
529
|
+
*/
|
|
530
|
+
this._popoverConfig = buildPopoverConfig({
|
|
531
|
+
cdkPositions: this._positions,
|
|
532
|
+
triggers: () => [],
|
|
533
|
+
noArrow: () => false,
|
|
534
|
+
closeOnEscapeKey: () => false,
|
|
535
|
+
closeOnOutsideClick: () => true,
|
|
536
|
+
disableScrollbar: () => true,
|
|
537
|
+
additionalBodyClass: () => [TOOLTIP_BODY_CLASS, this.fdTooltipBodyClass()].filter(Boolean).join(' '),
|
|
538
|
+
bodyRole: () => 'tooltip',
|
|
539
|
+
bodyId: () => this.tooltipId,
|
|
540
|
+
disabled: () => !this._enabled()
|
|
541
|
+
});
|
|
542
|
+
/**
|
|
543
|
+
* @hidden
|
|
544
|
+
* Hidden element in `document.body` that holds the screen reader description.
|
|
545
|
+
* `null` while the tooltip is disabled or has no content.
|
|
546
|
+
*/
|
|
547
|
+
this._descriptionElement = null;
|
|
548
|
+
/** @hidden Template content rendered into the hidden description element. */
|
|
549
|
+
this._descriptionView = null;
|
|
550
|
+
/** @hidden Whether this directive set `aria-keyshortcuts`, so it only removes an attribute it owns. */
|
|
551
|
+
this._keyShortcutsApplied = false;
|
|
552
|
+
/** @hidden Cleanup functions for the pointer listeners on the open tooltip overlay. */
|
|
553
|
+
this._bodyListeners = [];
|
|
554
|
+
/** @hidden Timer that detects a touch long-press. */
|
|
555
|
+
this._longPressTimer = null;
|
|
556
|
+
/** @hidden Whether `PopoverService.initialise()` was called; later changes use `refreshConfiguration()`. */
|
|
557
|
+
this._initialised = false;
|
|
558
|
+
effect(() => {
|
|
559
|
+
const config = this._popoverConfig();
|
|
560
|
+
untracked(() => {
|
|
561
|
+
if (this._initialised) {
|
|
562
|
+
this._popoverService.refreshConfiguration(config);
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
this._popoverService.initialise(this._elementRef, config);
|
|
566
|
+
this._initialised = true;
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
effect(() => {
|
|
571
|
+
const text = this._text();
|
|
572
|
+
const template = this._template();
|
|
573
|
+
untracked(() => this._popoverService.updateContent(template ? null : text, template));
|
|
574
|
+
});
|
|
575
|
+
effect((onCleanup) => {
|
|
576
|
+
const trigger = this.fdTooltipTrigger();
|
|
577
|
+
if (!this._enabled()) {
|
|
578
|
+
return;
|
|
579
|
+
}
|
|
580
|
+
const listeners = untracked(() => this._listenToHost(trigger));
|
|
581
|
+
onCleanup(() => untracked(() => {
|
|
582
|
+
listeners.forEach((unlisten) => unlisten());
|
|
583
|
+
this._clearLongPress();
|
|
584
|
+
this._coordinator.hide(this._handle, 0);
|
|
585
|
+
}));
|
|
586
|
+
});
|
|
587
|
+
afterRenderEffect(() => {
|
|
588
|
+
const enabled = this._enabled();
|
|
589
|
+
const description = this._description();
|
|
590
|
+
const template = this._template();
|
|
591
|
+
const keyShortcuts = this.fdTooltipKeyShortcuts();
|
|
592
|
+
this._updateAria(enabled ? description : '', enabled ? template : null, enabled ? keyShortcuts : null);
|
|
593
|
+
});
|
|
594
|
+
this._popoverService._onLoad.pipe(takeUntilDestroyed()).subscribe(({ nativeElement }) => {
|
|
595
|
+
this._setHostSize(nativeElement);
|
|
596
|
+
this._listenToBody(nativeElement);
|
|
597
|
+
});
|
|
598
|
+
inject(DestroyRef).onDestroy(() => {
|
|
599
|
+
this._coordinator.unregister(this._handle);
|
|
600
|
+
this._removeBodyListeners();
|
|
601
|
+
this._updateAria('', null, null);
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Shows the tooltip immediately, without the show delay, and closes any other open tooltip.
|
|
606
|
+
* Does nothing while the tooltip is disabled or has no content.
|
|
607
|
+
* Accessible from templates via `#ref="fdTooltip"`.
|
|
608
|
+
*/
|
|
609
|
+
show() {
|
|
610
|
+
if (this._enabled()) {
|
|
611
|
+
this._requestShow(0);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
/** Hides the tooltip immediately and cancels a pending show. */
|
|
615
|
+
hide() {
|
|
616
|
+
this._coordinator.hide(this._handle, 0);
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* @hidden
|
|
620
|
+
* Asks the coordinator to show this tooltip after `delay`. Refreshes `aria-describedby` first,
|
|
621
|
+
* because the host's accessible name may have changed since the last render.
|
|
622
|
+
*/
|
|
623
|
+
_requestShow(delay) {
|
|
624
|
+
this._syncDescribedBy();
|
|
625
|
+
this._coordinator.show(this._handle, delay, this._config.sequenceDelay);
|
|
626
|
+
}
|
|
627
|
+
/** @hidden Effective show delay: the `fdTooltipShowDelay` input, or the configured default. */
|
|
628
|
+
_showDelay() {
|
|
629
|
+
return this.fdTooltipShowDelay() ?? this._config.showDelay;
|
|
630
|
+
}
|
|
631
|
+
/** @hidden Effective hide delay: the `fdTooltipHideDelay` input, or the configured default. */
|
|
632
|
+
_hideDelay() {
|
|
633
|
+
return this.fdTooltipHideDelay() ?? this._config.hideDelay;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* @hidden
|
|
637
|
+
* Attaches the host listeners for the given trigger and returns their cleanup functions.
|
|
638
|
+
* Both triggers listen to `keydown` for `Ctrl+Alt+I` (Windows/Linux) / `Ctrl+Option+I` (Mac).
|
|
639
|
+
*
|
|
640
|
+
* `click` trigger:
|
|
641
|
+
* - `click`: toggles the tooltip immediately.
|
|
642
|
+
* - `focusout`: hides the tooltip when focus moves to another element.
|
|
643
|
+
*
|
|
644
|
+
* `hover` trigger:
|
|
645
|
+
* - `pointerenter` / `pointerleave` (mouse and pen only): show / hide with delay.
|
|
646
|
+
* - `focusin` / `focusout`: show on keyboard focus, hide when focus leaves the host.
|
|
647
|
+
* - `click` and `Enter`: hide immediately, because the host action was triggered.
|
|
648
|
+
* - `touchstart` / `touchmove` / `touchend` / `touchcancel`: detect a long-press.
|
|
649
|
+
*/
|
|
650
|
+
_listenToHost(trigger) {
|
|
651
|
+
const host = this._host;
|
|
652
|
+
const keydown = this._renderer.listen(host, 'keydown', (event) => this._onKeydown(event, trigger));
|
|
653
|
+
if (trigger === 'click') {
|
|
654
|
+
return [
|
|
655
|
+
keydown,
|
|
656
|
+
this._renderer.listen(host, 'click', () => this._toggle()),
|
|
657
|
+
this._renderer.listen(host, 'focusout', (event) => {
|
|
658
|
+
const target = event.relatedTarget;
|
|
659
|
+
// Clicking the tooltip text moves focus nowhere, so the tooltip stays open for text selection.
|
|
660
|
+
if (target && !host.contains(target)) {
|
|
661
|
+
this.hide();
|
|
662
|
+
}
|
|
663
|
+
})
|
|
664
|
+
];
|
|
665
|
+
}
|
|
666
|
+
const stopLongPress = () => this._clearLongPress();
|
|
667
|
+
return [
|
|
668
|
+
keydown,
|
|
669
|
+
this._renderer.listen(host, 'pointerenter', (event) => {
|
|
670
|
+
if (event.pointerType !== 'touch') {
|
|
671
|
+
this._requestShow(this._showDelay());
|
|
672
|
+
}
|
|
673
|
+
}),
|
|
674
|
+
this._renderer.listen(host, 'pointerleave', (event) => {
|
|
675
|
+
if (event.pointerType !== 'touch') {
|
|
676
|
+
this._coordinator.hide(this._handle, this._hideDelay());
|
|
677
|
+
}
|
|
678
|
+
}),
|
|
679
|
+
this._renderer.listen(host, 'focusin', (event) => this._onFocusIn(event)),
|
|
680
|
+
this._renderer.listen(host, 'focusout', (event) => {
|
|
681
|
+
if (!host.contains(event.relatedTarget)) {
|
|
682
|
+
this._coordinator.hide(this._handle, this._hideDelay());
|
|
683
|
+
}
|
|
684
|
+
}),
|
|
685
|
+
this._renderer.listen(host, 'click', () => this.hide()),
|
|
686
|
+
this._renderer.listen(host, 'touchstart', () => this._startLongPress(), { passive: true }),
|
|
687
|
+
this._renderer.listen(host, 'touchmove', stopLongPress, { passive: true }),
|
|
688
|
+
this._renderer.listen(host, 'touchend', stopLongPress),
|
|
689
|
+
this._renderer.listen(host, 'touchcancel', stopLongPress)
|
|
690
|
+
];
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* @hidden
|
|
694
|
+
* Shows the tooltip when the host receives keyboard focus. Ignores focus moving between elements
|
|
695
|
+
* inside the host, focus caused by a mouse click or touch, and focus restored by the browser when
|
|
696
|
+
* the window is activated again.
|
|
697
|
+
*/
|
|
698
|
+
_onFocusIn(event) {
|
|
699
|
+
if (this._host.contains(event.relatedTarget)) {
|
|
700
|
+
return;
|
|
701
|
+
}
|
|
702
|
+
if (this._coordinator.isWindowRefocus() || this._inputModality.mostRecentModality !== 'keyboard') {
|
|
703
|
+
return;
|
|
704
|
+
}
|
|
705
|
+
this._requestShow(this._showDelay());
|
|
706
|
+
}
|
|
707
|
+
/**
|
|
708
|
+
* @hidden
|
|
709
|
+
* Handles keyboard input on the host: `Ctrl+Alt+I` (Windows/Linux) / `Ctrl+Option+I` (Mac) toggles the tooltip without delay. With the `hover`
|
|
710
|
+
* trigger, `Enter` hides the tooltip because it triggers the host action; with the `click` trigger,
|
|
711
|
+
* `Enter` already toggles it through the resulting `click` event.
|
|
712
|
+
*/
|
|
713
|
+
_onKeydown(event, trigger) {
|
|
714
|
+
if (event.ctrlKey && event.altKey && event.code === 'KeyI') {
|
|
715
|
+
event.preventDefault();
|
|
716
|
+
this._toggle();
|
|
717
|
+
return;
|
|
718
|
+
}
|
|
719
|
+
if (trigger === 'hover' && KeyUtil.isKeyCode(event, ENTER)) {
|
|
720
|
+
this.hide();
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
/** @hidden Shows the tooltip immediately if it is hidden, hides it otherwise. */
|
|
724
|
+
_toggle() {
|
|
725
|
+
if (this._popoverService.isOpen()) {
|
|
726
|
+
this.hide();
|
|
727
|
+
}
|
|
728
|
+
else {
|
|
729
|
+
this.show();
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* @hidden
|
|
734
|
+
* Starts the long-press detection on touch. When the touch is held for `LONG_PRESS_DURATION`,
|
|
735
|
+
* the tooltip shows immediately. Skipped on links so the native link context menu keeps working.
|
|
736
|
+
*/
|
|
737
|
+
_startLongPress() {
|
|
738
|
+
this._clearLongPress();
|
|
739
|
+
if (this._host.matches('a[href]')) {
|
|
740
|
+
return;
|
|
741
|
+
}
|
|
742
|
+
this._longPressTimer = setTimeout(() => {
|
|
743
|
+
this._longPressTimer = null;
|
|
744
|
+
this._requestShow(0);
|
|
745
|
+
}, LONG_PRESS_DURATION);
|
|
746
|
+
}
|
|
747
|
+
/** @hidden Cancels the long-press detection, e.g. when the touch ends early or moves. */
|
|
748
|
+
_clearLongPress() {
|
|
749
|
+
if (this._longPressTimer !== null) {
|
|
750
|
+
clearTimeout(this._longPressTimer);
|
|
751
|
+
this._longPressTimer = null;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* @hidden
|
|
756
|
+
* Passes the host size to the tooltip styles, so that with `start`/`end` alignment
|
|
757
|
+
* the arrow points at the centre of the host instead of a fixed icon-button offset.
|
|
758
|
+
*/
|
|
759
|
+
_setHostSize(body) {
|
|
760
|
+
const { width, height } = this._host.getBoundingClientRect();
|
|
761
|
+
this._renderer.setStyle(body, '--fdTooltip_Host_Width', `${width}px`, RendererStyleFlags2.DashCase);
|
|
762
|
+
this._renderer.setStyle(body, '--fdTooltip_Host_Height', `${height}px`, RendererStyleFlags2.DashCase);
|
|
763
|
+
}
|
|
764
|
+
/**
|
|
765
|
+
* @hidden
|
|
766
|
+
* Attaches pointer listeners to the opened overlay, so the tooltip stays open while hovered
|
|
767
|
+
* (e.g. to select its text) and hides after the hide delay when the pointer leaves it.
|
|
768
|
+
* Not used with the `click` trigger, where the pointer position does not close the tooltip.
|
|
769
|
+
*/
|
|
770
|
+
_listenToBody(body) {
|
|
771
|
+
this._removeBodyListeners();
|
|
772
|
+
if (this.fdTooltipTrigger() === 'click') {
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
this._bodyListeners = [
|
|
776
|
+
this._renderer.listen(body, 'pointerenter', () => this._coordinator.cancelHide(this._handle)),
|
|
777
|
+
this._renderer.listen(body, 'pointerleave', () => this._coordinator.hide(this._handle, this._hideDelay()))
|
|
778
|
+
];
|
|
779
|
+
}
|
|
780
|
+
/** @hidden Removes the pointer listeners from the overlay. */
|
|
781
|
+
_removeBodyListeners() {
|
|
782
|
+
this._bodyListeners.forEach((unlisten) => unlisten());
|
|
783
|
+
this._bodyListeners = [];
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* @hidden
|
|
787
|
+
* Applies the ARIA state to the host:
|
|
788
|
+
* - fills the hidden description element with the text or the rendered template, or removes it,
|
|
789
|
+
* - adds or removes this tooltip's id in `aria-describedby`,
|
|
790
|
+
* - sets or removes `aria-keyshortcuts`.
|
|
791
|
+
* Empty text, no template and `null` shortcuts remove everything this directive added.
|
|
792
|
+
*/
|
|
793
|
+
_updateAria(text, template, keyShortcuts) {
|
|
794
|
+
this._descriptionView?.destroy();
|
|
795
|
+
this._descriptionView = null;
|
|
796
|
+
if (text || template) {
|
|
797
|
+
this._descriptionElement ??= this._createDescriptionElement();
|
|
798
|
+
this._descriptionElement.textContent = template ? '' : text;
|
|
799
|
+
if (template) {
|
|
800
|
+
this._renderDescriptionTemplate(this._descriptionElement, template);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
else if (this._descriptionElement) {
|
|
804
|
+
this._renderer.removeChild(this._document.body, this._descriptionElement);
|
|
805
|
+
this._descriptionElement = null;
|
|
806
|
+
}
|
|
807
|
+
this._syncDescribedBy();
|
|
808
|
+
if (keyShortcuts) {
|
|
809
|
+
this._renderer.setAttribute(this._host, 'aria-keyshortcuts', keyShortcuts);
|
|
810
|
+
}
|
|
811
|
+
else if (this._keyShortcutsApplied) {
|
|
812
|
+
this._renderer.removeAttribute(this._host, 'aria-keyshortcuts');
|
|
813
|
+
}
|
|
814
|
+
this._keyShortcutsApplied = !!keyShortcuts;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* @hidden
|
|
818
|
+
* Renders the template into the hidden description element, so screen readers announce the same
|
|
819
|
+
* content as shown in the tooltip. The view is attached to the application, so it stays up to date.
|
|
820
|
+
*/
|
|
821
|
+
_renderDescriptionTemplate(element, template) {
|
|
822
|
+
const view = template.createEmbeddedView(null);
|
|
823
|
+
this._appRef.attachView(view);
|
|
824
|
+
view.detectChanges();
|
|
825
|
+
view.rootNodes.forEach((node) => this._renderer.appendChild(element, node));
|
|
826
|
+
this._descriptionView = view;
|
|
827
|
+
}
|
|
828
|
+
/**
|
|
829
|
+
* @hidden
|
|
830
|
+
* Creates the hidden description element in `document.body`. It lives outside the host so the host's
|
|
831
|
+
* DOM and accessible name stay untouched; hidden content is still announced when referenced by
|
|
832
|
+
* `aria-describedby`.
|
|
833
|
+
*/
|
|
834
|
+
_createDescriptionElement() {
|
|
835
|
+
const element = this._renderer.createElement('span');
|
|
836
|
+
this._renderer.setAttribute(element, 'id', this._descriptionId);
|
|
837
|
+
this._renderer.setAttribute(element, 'hidden', '');
|
|
838
|
+
this._renderer.appendChild(this._document.body, element);
|
|
839
|
+
return element;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* @hidden
|
|
843
|
+
* Adds this tooltip's description id to the host's `aria-describedby` only when the description
|
|
844
|
+
* differs from the host's accessible name, so screen readers do not announce the same text twice.
|
|
845
|
+
* Ids added by others are always kept.
|
|
846
|
+
*/
|
|
847
|
+
_syncDescribedBy() {
|
|
848
|
+
const ids = (this._host.getAttribute('aria-describedby') ?? '')
|
|
849
|
+
.split(/\s+/)
|
|
850
|
+
.filter((id) => id && id !== this._descriptionId);
|
|
851
|
+
const description = this._descriptionElement?.textContent ?? '';
|
|
852
|
+
if (description && normalizeText(description) !== normalizeText(this._accessibleName())) {
|
|
853
|
+
ids.push(this._descriptionId);
|
|
854
|
+
}
|
|
855
|
+
if (ids.length) {
|
|
856
|
+
this._renderer.setAttribute(this._host, 'aria-describedby', ids.join(' '));
|
|
857
|
+
}
|
|
858
|
+
else {
|
|
859
|
+
this._renderer.removeAttribute(this._host, 'aria-describedby');
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
/**
|
|
863
|
+
* @hidden
|
|
864
|
+
* Approximates the host's accessible name for the duplicate-announcement check, using the first
|
|
865
|
+
* available source: `aria-labelledby`, `aria-label`, associated `<label>` elements, text content.
|
|
866
|
+
*/
|
|
867
|
+
_accessibleName() {
|
|
868
|
+
const host = this._host;
|
|
869
|
+
const labelledBy = host.getAttribute('aria-labelledby');
|
|
870
|
+
if (labelledBy) {
|
|
871
|
+
return labelledBy
|
|
872
|
+
.split(/\s+/)
|
|
873
|
+
.map((id) => this._document.getElementById(id)?.textContent ?? '')
|
|
874
|
+
.join(' ');
|
|
875
|
+
}
|
|
876
|
+
const ariaLabel = host.getAttribute('aria-label');
|
|
877
|
+
if (ariaLabel) {
|
|
878
|
+
return ariaLabel;
|
|
879
|
+
}
|
|
880
|
+
const labels = host.labels;
|
|
881
|
+
if (labels?.length) {
|
|
882
|
+
return Array.from(labels, (label) => label.textContent ?? '').join(' ');
|
|
883
|
+
}
|
|
884
|
+
return host.textContent ?? '';
|
|
885
|
+
}
|
|
886
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: TooltipDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
887
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.2.1", type: TooltipDirective, isStandalone: true, selector: "[fdTooltip]", inputs: { fdTooltip: { classPropertyName: "fdTooltip", publicName: "fdTooltip", isSignal: true, isRequired: false, transformFunction: null }, fdTooltipPlacement: { classPropertyName: "fdTooltipPlacement", publicName: "fdTooltipPlacement", isSignal: true, isRequired: false, transformFunction: null }, fdTooltipAlignment: { classPropertyName: "fdTooltipAlignment", publicName: "fdTooltipAlignment", isSignal: true, isRequired: false, transformFunction: null }, fdTooltipTrigger: { classPropertyName: "fdTooltipTrigger", publicName: "fdTooltipTrigger", isSignal: true, isRequired: false, transformFunction: null }, fdTooltipDisabled: { classPropertyName: "fdTooltipDisabled", publicName: "fdTooltipDisabled", isSignal: true, isRequired: false, transformFunction: null }, fdTooltipShowDelay: { classPropertyName: "fdTooltipShowDelay", publicName: "fdTooltipShowDelay", isSignal: true, isRequired: false, transformFunction: null }, fdTooltipHideDelay: { classPropertyName: "fdTooltipHideDelay", publicName: "fdTooltipHideDelay", isSignal: true, isRequired: false, transformFunction: null }, fdTooltipKeyShortcuts: { classPropertyName: "fdTooltipKeyShortcuts", publicName: "fdTooltipKeyShortcuts", isSignal: true, isRequired: false, transformFunction: null }, fdTooltipBodyClass: { classPropertyName: "fdTooltipBodyClass", publicName: "fdTooltipBodyClass", isSignal: true, isRequired: false, transformFunction: null } }, providers: [PopoverService], exportAs: ["fdTooltip"], ngImport: i0 }); }
|
|
888
|
+
}
|
|
889
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.1", ngImport: i0, type: TooltipDirective, decorators: [{
|
|
890
|
+
type: Directive,
|
|
891
|
+
args: [{
|
|
892
|
+
selector: '[fdTooltip]',
|
|
893
|
+
exportAs: 'fdTooltip',
|
|
894
|
+
providers: [PopoverService]
|
|
895
|
+
}]
|
|
896
|
+
}], ctorParameters: () => [], propDecorators: { fdTooltip: [{ type: i0.Input, args: [{ isSignal: true, alias: "fdTooltip", required: false }] }], fdTooltipPlacement: [{ type: i0.Input, args: [{ isSignal: true, alias: "fdTooltipPlacement", required: false }] }], fdTooltipAlignment: [{ type: i0.Input, args: [{ isSignal: true, alias: "fdTooltipAlignment", required: false }] }], fdTooltipTrigger: [{ type: i0.Input, args: [{ isSignal: true, alias: "fdTooltipTrigger", required: false }] }], fdTooltipDisabled: [{ type: i0.Input, args: [{ isSignal: true, alias: "fdTooltipDisabled", required: false }] }], fdTooltipShowDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "fdTooltipShowDelay", required: false }] }], fdTooltipHideDelay: [{ type: i0.Input, args: [{ isSignal: true, alias: "fdTooltipHideDelay", required: false }] }], fdTooltipKeyShortcuts: [{ type: i0.Input, args: [{ isSignal: true, alias: "fdTooltipKeyShortcuts", required: false }] }], fdTooltipBodyClass: [{ type: i0.Input, args: [{ isSignal: true, alias: "fdTooltipBodyClass", required: false }] }] } });
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* Generated bundle index. Do not edit.
|
|
900
|
+
*/
|
|
901
|
+
|
|
902
|
+
export { DEFAULT_TOOLTIP_CONFIG, TOOLTIP_CONFIG, TooltipCoordinator, TooltipDirective };
|
|
903
|
+
//# sourceMappingURL=fundamental-ngx-core-tooltip.mjs.map
|