@vaadin/tooltip 24.3.0-alpha1 → 24.3.0-alpha3

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.
@@ -0,0 +1,812 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) 2022 - 2023 Vaadin Ltd.
4
+ * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
+ */
6
+ import { isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
7
+ import { microTask } from '@vaadin/component-base/src/async.js';
8
+ import { Debouncer } from '@vaadin/component-base/src/debounce.js';
9
+ import { addValueToAttribute, removeValueFromAttribute } from '@vaadin/component-base/src/dom-utils.js';
10
+ import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
11
+ import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
12
+ import { generateUniqueId } from '@vaadin/component-base/src/unique-id-utils.js';
13
+
14
+ const DEFAULT_DELAY = 500;
15
+
16
+ let defaultFocusDelay = DEFAULT_DELAY;
17
+ let defaultHoverDelay = DEFAULT_DELAY;
18
+ let defaultHideDelay = DEFAULT_DELAY;
19
+
20
+ const closing = new Set();
21
+
22
+ let warmedUp = false;
23
+ let warmUpTimeout = null;
24
+ let cooldownTimeout = null;
25
+
26
+ /**
27
+ * Resets the global tooltip warmup and cooldown state.
28
+ * Only for internal use in tests.
29
+ * @private
30
+ */
31
+ export function resetGlobalTooltipState() {
32
+ warmedUp = false;
33
+ clearTimeout(warmUpTimeout);
34
+ clearTimeout(cooldownTimeout);
35
+ closing.clear();
36
+ }
37
+
38
+ /**
39
+ * Controller for handling tooltip opened state.
40
+ */
41
+ class TooltipStateController {
42
+ constructor(host) {
43
+ this.host = host;
44
+ }
45
+
46
+ /** @private */
47
+ get openedProp() {
48
+ return this.host.manual ? 'opened' : '_autoOpened';
49
+ }
50
+
51
+ /** @private */
52
+ get focusDelay() {
53
+ const tooltip = this.host;
54
+ return tooltip.focusDelay != null && tooltip.focusDelay > 0 ? tooltip.focusDelay : defaultFocusDelay;
55
+ }
56
+
57
+ /** @private */
58
+ get hoverDelay() {
59
+ const tooltip = this.host;
60
+ return tooltip.hoverDelay != null && tooltip.hoverDelay > 0 ? tooltip.hoverDelay : defaultHoverDelay;
61
+ }
62
+
63
+ /** @private */
64
+ get hideDelay() {
65
+ const tooltip = this.host;
66
+ return tooltip.hideDelay != null && tooltip.hideDelay > 0 ? tooltip.hideDelay : defaultHideDelay;
67
+ }
68
+
69
+ /**
70
+ * Whether closing is currently in progress.
71
+ * @return {boolean}
72
+ */
73
+ get isClosing() {
74
+ return closing.has(this.host);
75
+ }
76
+
77
+ /**
78
+ * Schedule opening the tooltip.
79
+ * @param {Object} options
80
+ */
81
+ open(options = { immediate: false }) {
82
+ const { immediate, hover, focus } = options;
83
+ const isHover = hover && this.hoverDelay > 0;
84
+ const isFocus = focus && this.focusDelay > 0;
85
+
86
+ if (!immediate && (isHover || isFocus) && !this.__closeTimeout) {
87
+ this.__warmupTooltip(isFocus);
88
+ } else {
89
+ this.__showTooltip();
90
+ }
91
+ }
92
+
93
+ /**
94
+ * Schedule closing the tooltip.
95
+ * @param {boolean} immediate
96
+ */
97
+ close(immediate) {
98
+ if (!immediate && this.hideDelay > 0) {
99
+ this.__scheduleClose();
100
+ } else {
101
+ this.__abortClose();
102
+ this._setOpened(false);
103
+ }
104
+
105
+ this.__abortWarmUp();
106
+
107
+ if (warmedUp) {
108
+ // Re-start cooldown timer on each tooltip closing.
109
+ this.__abortCooldown();
110
+ this.__scheduleCooldown();
111
+ }
112
+ }
113
+
114
+ /** @private */
115
+ _isOpened() {
116
+ return this.host[this.openedProp];
117
+ }
118
+
119
+ /** @private */
120
+ _setOpened(opened) {
121
+ this.host[this.openedProp] = opened;
122
+ }
123
+
124
+ /** @private */
125
+ __flushClosingTooltips() {
126
+ closing.forEach((tooltip) => {
127
+ tooltip._stateController.close(true);
128
+ closing.delete(tooltip);
129
+ });
130
+ }
131
+
132
+ /** @private */
133
+ __showTooltip() {
134
+ this.__abortClose();
135
+ this.__flushClosingTooltips();
136
+
137
+ this._setOpened(true);
138
+ warmedUp = true;
139
+
140
+ // Abort previously scheduled timers.
141
+ this.__abortWarmUp();
142
+ this.__abortCooldown();
143
+ }
144
+
145
+ /** @private */
146
+ __warmupTooltip(isFocus) {
147
+ if (!this._isOpened()) {
148
+ // First tooltip is opened, warm up.
149
+ if (!warmedUp) {
150
+ this.__scheduleWarmUp(isFocus);
151
+ } else {
152
+ // Warmed up, show another tooltip.
153
+ this.__showTooltip();
154
+ }
155
+ }
156
+ }
157
+
158
+ /** @private */
159
+ __abortClose() {
160
+ if (this.__closeTimeout) {
161
+ clearTimeout(this.__closeTimeout);
162
+ this.__closeTimeout = null;
163
+ }
164
+ }
165
+
166
+ /** @private */
167
+ __abortCooldown() {
168
+ if (cooldownTimeout) {
169
+ clearTimeout(cooldownTimeout);
170
+ cooldownTimeout = null;
171
+ }
172
+ }
173
+
174
+ /** @private */
175
+ __abortWarmUp() {
176
+ if (warmUpTimeout) {
177
+ clearTimeout(warmUpTimeout);
178
+ warmUpTimeout = null;
179
+ }
180
+ }
181
+
182
+ /** @private */
183
+ __scheduleClose() {
184
+ if (this._isOpened()) {
185
+ closing.add(this.host);
186
+
187
+ this.__closeTimeout = setTimeout(() => {
188
+ closing.delete(this.host);
189
+ this.__closeTimeout = null;
190
+ this._setOpened(false);
191
+ }, this.hideDelay);
192
+ }
193
+ }
194
+
195
+ /** @private */
196
+ __scheduleCooldown() {
197
+ cooldownTimeout = setTimeout(() => {
198
+ cooldownTimeout = null;
199
+ warmedUp = false;
200
+ }, this.hideDelay);
201
+ }
202
+
203
+ /** @private */
204
+ __scheduleWarmUp(isFocus) {
205
+ const delay = isFocus ? this.focusDelay : this.hoverDelay;
206
+ warmUpTimeout = setTimeout(() => {
207
+ warmUpTimeout = null;
208
+ warmedUp = true;
209
+ this.__showTooltip();
210
+ }, delay);
211
+ }
212
+ }
213
+
214
+ /**
215
+ * A mixin providing common tooltip functionality.
216
+ *
217
+ * @polymerMixin
218
+ * @mixes OverlayClassMixin
219
+ */
220
+ export const TooltipMixin = (superClass) =>
221
+ class TooltipMixinClass extends OverlayClassMixin(superClass) {
222
+ static get properties() {
223
+ return {
224
+ /**
225
+ * Element used to link with the `aria-describedby`
226
+ * attribute. Supports array of multiple elements.
227
+ * When not set, defaults to `target`.
228
+ */
229
+ ariaTarget: {
230
+ type: Object,
231
+ },
232
+
233
+ /**
234
+ * Object with properties passed to `generator` and
235
+ * `shouldShow` functions for generating tooltip text
236
+ * or detecting whether to show the tooltip or not.
237
+ */
238
+ context: {
239
+ type: Object,
240
+ value: () => {
241
+ return {};
242
+ },
243
+ },
244
+
245
+ /**
246
+ * The delay in milliseconds before the tooltip
247
+ * is opened on keyboard focus, when not in manual mode.
248
+ * @attr {number} focus-delay
249
+ */
250
+ focusDelay: {
251
+ type: Number,
252
+ },
253
+
254
+ /**
255
+ * The id of the element used as a tooltip trigger.
256
+ * The element should be in the DOM by the time when
257
+ * the attribute is set, otherwise a warning is shown.
258
+ */
259
+ for: {
260
+ type: String,
261
+ observer: '__forChanged',
262
+ },
263
+
264
+ /**
265
+ * Function used to generate the tooltip content.
266
+ * When provided, it overrides the `text` property.
267
+ * Use the `context` property to provide argument
268
+ * that can be passed to the generator function.
269
+ */
270
+ generator: {
271
+ type: Object,
272
+ },
273
+
274
+ /**
275
+ * The delay in milliseconds before the tooltip
276
+ * is closed on losing hover, when not in manual mode.
277
+ * On blur, the tooltip is closed immediately.
278
+ * @attr {number} hide-delay
279
+ */
280
+ hideDelay: {
281
+ type: Number,
282
+ },
283
+
284
+ /**
285
+ * The delay in milliseconds before the tooltip
286
+ * is opened on hover, when not in manual mode.
287
+ * @attr {number} hover-delay
288
+ */
289
+ hoverDelay: {
290
+ type: Number,
291
+ },
292
+
293
+ /**
294
+ * When true, the tooltip is controlled programmatically
295
+ * instead of reacting to focus and mouse events.
296
+ */
297
+ manual: {
298
+ type: Boolean,
299
+ value: false,
300
+ sync: true,
301
+ },
302
+
303
+ /**
304
+ * When true, the tooltip is opened programmatically.
305
+ * Only works if `manual` is set to `true`.
306
+ */
307
+ opened: {
308
+ type: Boolean,
309
+ value: false,
310
+ sync: true,
311
+ },
312
+
313
+ /**
314
+ * Position of the tooltip with respect to its target.
315
+ * Supported values: `top-start`, `top`, `top-end`,
316
+ * `bottom-start`, `bottom`, `bottom-end`, `start-top`,
317
+ * `start`, `start-bottom`, `end-top`, `end`, `end-bottom`.
318
+ */
319
+ position: {
320
+ type: String,
321
+ },
322
+
323
+ /**
324
+ * Function used to detect whether to show the tooltip based on a condition,
325
+ * called every time the tooltip is about to be shown on hover and focus.
326
+ * The function takes two parameters: `target` and `context`, which contain
327
+ * values of the corresponding tooltip properties at the time of calling.
328
+ * The tooltip is only shown when the function invocation returns `true`.
329
+ */
330
+ shouldShow: {
331
+ type: Object,
332
+ value: () => {
333
+ return (_target, _context) => true;
334
+ },
335
+ },
336
+
337
+ /**
338
+ * Reference to the element used as a tooltip trigger.
339
+ * The target must be placed in the same shadow scope.
340
+ * Defaults to an element referenced with `for`.
341
+ */
342
+ target: {
343
+ type: Object,
344
+ observer: '__targetChanged',
345
+ },
346
+
347
+ /**
348
+ * String used as a tooltip content.
349
+ */
350
+ text: {
351
+ type: String,
352
+ observer: '__textChanged',
353
+ },
354
+
355
+ /**
356
+ * Set to true when the overlay is opened using auto-added
357
+ * event listeners: mouseenter and focusin (keyboard only).
358
+ * @protected
359
+ */
360
+ _autoOpened: {
361
+ type: Boolean,
362
+ observer: '__autoOpenedChanged',
363
+ sync: true,
364
+ },
365
+
366
+ /**
367
+ * Element used to link with the `aria-describedby`
368
+ * attribute. When not set, defaults to `target`.
369
+ * @protected
370
+ */
371
+ _effectiveAriaTarget: {
372
+ type: Object,
373
+ computed: '__computeAriaTarget(ariaTarget, target)',
374
+ observer: '__effectiveAriaTargetChanged',
375
+ },
376
+
377
+ /** @private */
378
+ __effectivePosition: {
379
+ type: String,
380
+ computed: '__computePosition(position, _position)',
381
+ },
382
+
383
+ /** @private */
384
+ __isTargetHidden: {
385
+ type: Boolean,
386
+ value: false,
387
+ },
388
+
389
+ /** @private */
390
+ _isConnected: {
391
+ type: Boolean,
392
+ sync: true,
393
+ },
394
+
395
+ /**
396
+ * Default value used when `position` property is not set.
397
+ * @protected
398
+ */
399
+ _position: {
400
+ type: String,
401
+ value: 'bottom',
402
+ },
403
+
404
+ /** @private */
405
+ _srLabel: {
406
+ type: Object,
407
+ },
408
+
409
+ /** @private */
410
+ _overlayContent: {
411
+ type: String,
412
+ },
413
+ };
414
+ }
415
+
416
+ static get observers() {
417
+ return [
418
+ '__generatorChanged(_overlayElement, generator, context)',
419
+ '__updateSrLabelText(_srLabel, _overlayContent)',
420
+ ];
421
+ }
422
+
423
+ /**
424
+ * Sets the default focus delay to be used by all tooltip instances,
425
+ * except for those that have focus delay configured using property.
426
+ *
427
+ * @param {number} delay
428
+ */
429
+ static setDefaultFocusDelay(focusDelay) {
430
+ defaultFocusDelay = focusDelay != null && focusDelay >= 0 ? focusDelay : DEFAULT_DELAY;
431
+ }
432
+
433
+ /**
434
+ * Sets the default hide delay to be used by all tooltip instances,
435
+ * except for those that have hide delay configured using property.
436
+ *
437
+ * @param {number} hideDelay
438
+ */
439
+ static setDefaultHideDelay(hideDelay) {
440
+ defaultHideDelay = hideDelay != null && hideDelay >= 0 ? hideDelay : DEFAULT_DELAY;
441
+ }
442
+
443
+ /**
444
+ * Sets the default hover delay to be used by all tooltip instances,
445
+ * except for those that have hover delay configured using property.
446
+ *
447
+ * @param {number} delay
448
+ */
449
+ static setDefaultHoverDelay(hoverDelay) {
450
+ defaultHoverDelay = hoverDelay != null && hoverDelay >= 0 ? hoverDelay : DEFAULT_DELAY;
451
+ }
452
+
453
+ constructor() {
454
+ super();
455
+
456
+ this._uniqueId = `vaadin-tooltip-${generateUniqueId()}`;
457
+ this._renderer = this.__tooltipRenderer.bind(this);
458
+
459
+ this.__onFocusin = this.__onFocusin.bind(this);
460
+ this.__onFocusout = this.__onFocusout.bind(this);
461
+ this.__onMouseDown = this.__onMouseDown.bind(this);
462
+ this.__onMouseEnter = this.__onMouseEnter.bind(this);
463
+ this.__onMouseLeave = this.__onMouseLeave.bind(this);
464
+ this.__onKeyDown = this.__onKeyDown.bind(this);
465
+ this.__onOverlayOpen = this.__onOverlayOpen.bind(this);
466
+
467
+ this.__targetVisibilityObserver = new IntersectionObserver(
468
+ (entries) => {
469
+ entries.forEach((entry) => this.__onTargetVisibilityChange(entry.isIntersecting));
470
+ },
471
+ { threshold: 0 },
472
+ );
473
+
474
+ this._stateController = new TooltipStateController(this);
475
+ }
476
+
477
+ /** @protected */
478
+ connectedCallback() {
479
+ super.connectedCallback();
480
+
481
+ this._isConnected = true;
482
+
483
+ document.body.addEventListener('vaadin-overlay-open', this.__onOverlayOpen);
484
+ }
485
+
486
+ /** @protected */
487
+ disconnectedCallback() {
488
+ super.disconnectedCallback();
489
+
490
+ if (this._autoOpened) {
491
+ this._stateController.close(true);
492
+ }
493
+ this._isConnected = false;
494
+
495
+ document.body.removeEventListener('vaadin-overlay-open', this.__onOverlayOpen);
496
+ }
497
+
498
+ /** @protected */
499
+ ready() {
500
+ super.ready();
501
+
502
+ this._srLabelController = new SlotController(this, 'sr-label', 'div', {
503
+ initializer: (element) => {
504
+ element.id = this._uniqueId;
505
+ element.setAttribute('role', 'tooltip');
506
+ this._srLabel = element;
507
+ },
508
+ });
509
+ this.addController(this._srLabelController);
510
+ }
511
+
512
+ /** @private */
513
+ __computeHorizontalAlign(position) {
514
+ return ['top-end', 'bottom-end', 'start-top', 'start', 'start-bottom'].includes(position) ? 'end' : 'start';
515
+ }
516
+
517
+ /** @private */
518
+ __computeNoHorizontalOverlap(position) {
519
+ return ['start-top', 'start', 'start-bottom', 'end-top', 'end', 'end-bottom'].includes(position);
520
+ }
521
+
522
+ /** @private */
523
+ __computeNoVerticalOverlap(position) {
524
+ return ['top-start', 'top-end', 'top', 'bottom-start', 'bottom', 'bottom-end'].includes(position);
525
+ }
526
+
527
+ /** @private */
528
+ __computeVerticalAlign(position) {
529
+ return ['top-start', 'top-end', 'top', 'start-bottom', 'end-bottom'].includes(position) ? 'bottom' : 'top';
530
+ }
531
+
532
+ /** @private */
533
+ __computeOpened(manual, opened, autoOpened, connected) {
534
+ return connected && (manual ? opened : autoOpened);
535
+ }
536
+
537
+ /** @private */
538
+ __computePosition(position, defaultPosition) {
539
+ return position || defaultPosition;
540
+ }
541
+
542
+ /** @private */
543
+ __autoOpenedChanged(opened, oldOpened) {
544
+ if (opened) {
545
+ document.addEventListener('keydown', this.__onKeyDown, true);
546
+ } else if (oldOpened) {
547
+ document.removeEventListener('keydown', this.__onKeyDown, true);
548
+ }
549
+ }
550
+
551
+ /** @private */
552
+ __forChanged(forId) {
553
+ if (forId) {
554
+ this.__setTargetByIdDebouncer = Debouncer.debounce(this.__setTargetByIdDebouncer, microTask, () =>
555
+ this.__setTargetById(forId),
556
+ );
557
+ }
558
+ }
559
+
560
+ /** @private */
561
+ __setTargetById(targetId) {
562
+ if (!this.isConnected) {
563
+ return;
564
+ }
565
+
566
+ const target = this.getRootNode().getElementById(targetId);
567
+
568
+ if (target) {
569
+ this.target = target;
570
+ } else {
571
+ console.warn(`No element with id="${targetId}" found to show tooltip.`);
572
+ }
573
+ }
574
+
575
+ /** @private */
576
+ __targetChanged(target, oldTarget) {
577
+ if (oldTarget) {
578
+ oldTarget.removeEventListener('mouseenter', this.__onMouseEnter);
579
+ oldTarget.removeEventListener('mouseleave', this.__onMouseLeave);
580
+ oldTarget.removeEventListener('focusin', this.__onFocusin);
581
+ oldTarget.removeEventListener('focusout', this.__onFocusout);
582
+ oldTarget.removeEventListener('mousedown', this.__onMouseDown);
583
+
584
+ this.__targetVisibilityObserver.unobserve(oldTarget);
585
+ }
586
+
587
+ if (target) {
588
+ target.addEventListener('mouseenter', this.__onMouseEnter);
589
+ target.addEventListener('mouseleave', this.__onMouseLeave);
590
+ target.addEventListener('focusin', this.__onFocusin);
591
+ target.addEventListener('focusout', this.__onFocusout);
592
+ target.addEventListener('mousedown', this.__onMouseDown);
593
+
594
+ // Wait before observing to avoid Chrome issue.
595
+ requestAnimationFrame(() => {
596
+ this.__targetVisibilityObserver.observe(target);
597
+ });
598
+ }
599
+ }
600
+
601
+ /** @private */
602
+ __onFocusin(event) {
603
+ if (this.manual) {
604
+ return;
605
+ }
606
+
607
+ // Only open on keyboard focus.
608
+ if (!isKeyboardActive()) {
609
+ return;
610
+ }
611
+
612
+ // Do not re-open while focused if closed on Esc or mousedown.
613
+ if (this.target.contains(event.relatedTarget)) {
614
+ return;
615
+ }
616
+
617
+ if (!this.__isShouldShow()) {
618
+ return;
619
+ }
620
+
621
+ this.__focusInside = true;
622
+
623
+ if (!this.__isTargetHidden && (!this.__hoverInside || !this._autoOpened)) {
624
+ this._stateController.open({ focus: true });
625
+ }
626
+ }
627
+
628
+ /** @private */
629
+ __onFocusout(event) {
630
+ if (this.manual) {
631
+ return;
632
+ }
633
+
634
+ // Do not close when moving focus within a component.
635
+ if (this.target.contains(event.relatedTarget)) {
636
+ return;
637
+ }
638
+
639
+ this.__focusInside = false;
640
+
641
+ if (!this.__hoverInside) {
642
+ this._stateController.close(true);
643
+ }
644
+ }
645
+
646
+ /** @private */
647
+ __onKeyDown(event) {
648
+ if (event.key === 'Escape') {
649
+ event.stopPropagation();
650
+ this._stateController.close(true);
651
+ }
652
+ }
653
+
654
+ /** @private */
655
+ __onMouseDown() {
656
+ this._stateController.close(true);
657
+ }
658
+
659
+ /** @private */
660
+ __onMouseEnter() {
661
+ if (this.manual) {
662
+ return;
663
+ }
664
+
665
+ if (!this.__isShouldShow()) {
666
+ return;
667
+ }
668
+
669
+ if (this.__hoverInside) {
670
+ // Already hovering inside the element, do nothing.
671
+ return;
672
+ }
673
+
674
+ this.__hoverInside = true;
675
+
676
+ if (!this.__isTargetHidden && (!this.__focusInside || !this._autoOpened)) {
677
+ this._stateController.open({ hover: true });
678
+ }
679
+ }
680
+
681
+ /** @private */
682
+ __onMouseLeave(event) {
683
+ if (event.relatedTarget !== this._overlayElement) {
684
+ this.__handleMouseLeave();
685
+ }
686
+ }
687
+
688
+ /** @protected */
689
+ __onOverlayMouseEnter() {
690
+ // Retain opened state when moving pointer over the overlay.
691
+ // Closing can start due to an offset between the target and
692
+ // the overlay itself. If that's the case, re-open overlay.
693
+ // See https://github.com/vaadin/web-components/issues/6316
694
+ if (this._stateController.isClosing) {
695
+ this._stateController.open({ immediate: true });
696
+ }
697
+ }
698
+
699
+ /** @protected */
700
+ __onOverlayMouseLeave(event) {
701
+ if (event.relatedTarget !== this.target) {
702
+ this.__handleMouseLeave();
703
+ }
704
+ }
705
+
706
+ /** @private */
707
+ __handleMouseLeave() {
708
+ if (this.manual) {
709
+ return;
710
+ }
711
+
712
+ this.__hoverInside = false;
713
+
714
+ if (!this.__focusInside) {
715
+ this._stateController.close();
716
+ }
717
+ }
718
+
719
+ /** @private */
720
+ __onOverlayOpen() {
721
+ if (this.manual) {
722
+ return;
723
+ }
724
+
725
+ // Close tooltip if another overlay is opened on top of the tooltip's overlay
726
+ if (this._overlayElement.opened && !this._overlayElement._last) {
727
+ this._stateController.close(true);
728
+ }
729
+ }
730
+
731
+ /** @private */
732
+ __onTargetVisibilityChange(isVisible) {
733
+ const oldHidden = this.__isTargetHidden;
734
+ this.__isTargetHidden = !isVisible;
735
+
736
+ // Open the overlay when the target becomes visible and has focus or hover.
737
+ if (oldHidden && isVisible && (this.__focusInside || this.__hoverInside)) {
738
+ this._stateController.open({ immediate: true });
739
+ return;
740
+ }
741
+
742
+ // Close the overlay when the target is no longer fully visible.
743
+ if (!isVisible && this._autoOpened) {
744
+ this._stateController.close(true);
745
+ }
746
+ }
747
+
748
+ /** @private */
749
+ __isShouldShow() {
750
+ if (typeof this.shouldShow === 'function' && this.shouldShow(this.target, this.context) !== true) {
751
+ return false;
752
+ }
753
+
754
+ return true;
755
+ }
756
+
757
+ /** @private */
758
+ __textChanged(text, oldText) {
759
+ if (this._overlayElement && (text || oldText)) {
760
+ this._overlayElement.requestContentUpdate();
761
+ }
762
+ }
763
+
764
+ /** @private */
765
+ __tooltipRenderer(root) {
766
+ root.textContent = typeof this.generator === 'function' ? this.generator(this.context) : this.text;
767
+
768
+ // Update the sr-only label text content
769
+ this._overlayContent = root.textContent;
770
+ }
771
+
772
+ /** @private */
773
+ __computeAriaTarget(ariaTarget, target) {
774
+ const isElementNode = (el) => el && el.nodeType === Node.ELEMENT_NODE;
775
+ const isAriaTargetSet = Array.isArray(ariaTarget) ? ariaTarget.some(isElementNode) : ariaTarget;
776
+ return isAriaTargetSet ? ariaTarget : target;
777
+ }
778
+
779
+ /** @private */
780
+ __effectiveAriaTargetChanged(ariaTarget, oldAriaTarget) {
781
+ if (oldAriaTarget) {
782
+ [oldAriaTarget].flat().forEach((target) => {
783
+ removeValueFromAttribute(target, 'aria-describedby', this._uniqueId);
784
+ });
785
+ }
786
+
787
+ if (ariaTarget) {
788
+ [ariaTarget].flat().forEach((target) => {
789
+ addValueToAttribute(target, 'aria-describedby', this._uniqueId);
790
+ });
791
+ }
792
+ }
793
+
794
+ /** @private */
795
+ __generatorChanged(overlayElement, generator, context) {
796
+ if (overlayElement) {
797
+ if (generator !== this.__oldTextGenerator || context !== this.__oldContext) {
798
+ overlayElement.requestContentUpdate();
799
+ }
800
+
801
+ this.__oldTextGenerator = generator;
802
+ this.__oldContext = context;
803
+ }
804
+ }
805
+
806
+ /** @private */
807
+ __updateSrLabelText(srLabel, textContent) {
808
+ if (srLabel) {
809
+ srLabel.textContent = textContent;
810
+ }
811
+ }
812
+ };