@vaadin/tooltip 24.2.0-alpha9 → 24.2.0-beta2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/tooltip",
3
- "version": "24.2.0-alpha9",
3
+ "version": "24.2.0-beta2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -35,12 +35,12 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@polymer/polymer": "^3.0.0",
38
- "@vaadin/a11y-base": "24.2.0-alpha9",
39
- "@vaadin/component-base": "24.2.0-alpha9",
40
- "@vaadin/overlay": "24.2.0-alpha9",
41
- "@vaadin/vaadin-lumo-styles": "24.2.0-alpha9",
42
- "@vaadin/vaadin-material-styles": "24.2.0-alpha9",
43
- "@vaadin/vaadin-themable-mixin": "24.2.0-alpha9"
38
+ "@vaadin/a11y-base": "24.2.0-beta2",
39
+ "@vaadin/component-base": "24.2.0-beta2",
40
+ "@vaadin/overlay": "24.2.0-beta2",
41
+ "@vaadin/vaadin-lumo-styles": "24.2.0-beta2",
42
+ "@vaadin/vaadin-material-styles": "24.2.0-beta2",
43
+ "@vaadin/vaadin-themable-mixin": "24.2.0-beta2"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@esm-bundle/chai": "^4.3.4",
@@ -51,5 +51,5 @@
51
51
  "web-types.json",
52
52
  "web-types.lit.json"
53
53
  ],
54
- "gitHead": "e9765733fea96542e379e02e6f42b07145893140"
54
+ "gitHead": "4b852f9a12d4dade7f0fb3c73b7212436cebf310"
55
55
  }
@@ -4,6 +4,7 @@
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
6
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
+ import { defineCustomElement } from '@vaadin/component-base/src/define.js';
7
8
  import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
8
9
  import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js';
9
10
  import { PositionMixin } from '@vaadin/overlay/src/vaadin-overlay-position-mixin.js';
@@ -53,6 +54,7 @@ registerStyles('vaadin-tooltip-overlay', [overlayStyles, tooltipOverlayStyles],
53
54
  /**
54
55
  * An element used internally by `<vaadin-tooltip>`. Not intended to be used separately.
55
56
  *
57
+ * @customElement
56
58
  * @extends HTMLElement
57
59
  * @mixes DirMixin
58
60
  * @mixes OverlayMixin
@@ -155,4 +157,4 @@ class TooltipOverlay extends PositionMixin(OverlayMixin(DirMixin(ThemableMixin(P
155
157
  }
156
158
  }
157
159
 
158
- customElements.define(TooltipOverlay.is, TooltipOverlay);
160
+ defineCustomElement(TooltipOverlay);
@@ -3,6 +3,7 @@
3
3
  * Copyright (c) 2022 - 2023 Vaadin Ltd.
4
4
  * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5
5
  */
6
+ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
6
7
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
7
8
  import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
8
9
  import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
@@ -59,7 +60,7 @@ export type TooltipPosition =
59
60
  *
60
61
  * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
61
62
  */
62
- declare class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(HTMLElement))) {
63
+ declare class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ControllerMixin(ElementMixin(HTMLElement)))) {
63
64
  /**
64
65
  * Sets the default focus delay to be used by all tooltip instances,
65
66
  * except for those that have focus delay configured using property.
@@ -78,6 +79,13 @@ declare class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(
78
79
  */
79
80
  static setDefaultHoverDelay(delay: number): void;
80
81
 
82
+ /**
83
+ * Element used to link with the `aria-describedby`
84
+ * attribute. Supports array of multiple elements.
85
+ * When not set, defaults to `target`.
86
+ */
87
+ ariaTarget: HTMLElement | HTMLElement[] | undefined;
88
+
81
89
  /**
82
90
  * Object with properties passed to `generator` and
83
91
  * `shouldShow` functions for generating tooltip text
@@ -7,10 +7,13 @@ import './vaadin-tooltip-overlay.js';
7
7
  import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
8
8
  import { isKeyboardActive } from '@vaadin/a11y-base/src/focus-utils.js';
9
9
  import { microTask } from '@vaadin/component-base/src/async.js';
10
+ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
10
11
  import { Debouncer } from '@vaadin/component-base/src/debounce.js';
12
+ import { defineCustomElement } from '@vaadin/component-base/src/define.js';
11
13
  import { addValueToAttribute, removeValueFromAttribute } from '@vaadin/component-base/src/dom-utils.js';
12
14
  import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
13
15
  import { OverlayClassMixin } from '@vaadin/component-base/src/overlay-class-mixin.js';
16
+ import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
14
17
  import { generateUniqueId } from '@vaadin/component-base/src/unique-id-utils.js';
15
18
  import { ThemePropertyMixin } from '@vaadin/vaadin-themable-mixin/vaadin-theme-property-mixin.js';
16
19
 
@@ -69,6 +72,14 @@ class TooltipStateController {
69
72
  return tooltip.hideDelay != null && tooltip.hideDelay > 0 ? tooltip.hideDelay : defaultHideDelay;
70
73
  }
71
74
 
75
+ /**
76
+ * Whether closing is currently in progress.
77
+ * @return {boolean}
78
+ */
79
+ get isClosing() {
80
+ return closing.has(this.host);
81
+ }
82
+
72
83
  /**
73
84
  * Schedule opening the tooltip.
74
85
  * @param {Object} options
@@ -244,12 +255,14 @@ class TooltipStateController {
244
255
  *
245
256
  * See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
246
257
  *
258
+ * @customElement
247
259
  * @extends HTMLElement
260
+ * @mixes ControllerMixin
248
261
  * @mixes ElementMixin
249
262
  * @mixes OverlayClassMixin
250
263
  * @mixes ThemePropertyMixin
251
264
  */
252
- class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerElement))) {
265
+ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(ControllerMixin(PolymerElement)))) {
253
266
  static get is() {
254
267
  return 'vaadin-tooltip';
255
268
  }
@@ -262,8 +275,6 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
262
275
  }
263
276
  </style>
264
277
  <vaadin-tooltip-overlay
265
- id="[[_uniqueId]]"
266
- role="tooltip"
267
278
  renderer="[[_renderer]]"
268
279
  theme$="[[_theme]]"
269
280
  opened="[[__computeOpened(manual, opened, _autoOpened, _isConnected)]]"
@@ -273,14 +284,26 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
273
284
  no-vertical-overlap$="[[__computeNoVerticalOverlap(__effectivePosition)]]"
274
285
  horizontal-align="[[__computeHorizontalAlign(__effectivePosition)]]"
275
286
  vertical-align="[[__computeVerticalAlign(__effectivePosition)]]"
287
+ on-mouseenter="__onOverlayMouseEnter"
276
288
  on-mouseleave="__onOverlayMouseLeave"
277
289
  modeless
278
290
  ></vaadin-tooltip-overlay>
291
+
292
+ <slot name="sr-label"></slot>
279
293
  `;
280
294
  }
281
295
 
282
296
  static get properties() {
283
297
  return {
298
+ /**
299
+ * Element used to link with the `aria-describedby`
300
+ * attribute. Supports array of multiple elements.
301
+ * When not set, defaults to `target`.
302
+ */
303
+ ariaTarget: {
304
+ type: Object,
305
+ },
306
+
284
307
  /**
285
308
  * Object with properties passed to `generator` and
286
309
  * `shouldShow` functions for generating tooltip text
@@ -420,6 +443,17 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
420
443
  value: 'bottom',
421
444
  },
422
445
 
446
+ /**
447
+ * Element used to link with the `aria-describedby`
448
+ * attribute. When not set, defaults to `target`.
449
+ * @protected
450
+ */
451
+ _effectiveAriaTarget: {
452
+ type: Object,
453
+ computed: '__computeAriaTarget(ariaTarget, target)',
454
+ observer: '__effectiveAriaTargetChanged',
455
+ },
456
+
423
457
  /** @private */
424
458
  __effectivePosition: {
425
459
  type: String,
@@ -436,11 +470,24 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
436
470
  _isConnected: {
437
471
  type: Boolean,
438
472
  },
473
+
474
+ /** @private */
475
+ _srLabel: {
476
+ type: Object,
477
+ },
478
+
479
+ /** @private */
480
+ _overlayContent: {
481
+ type: String,
482
+ },
439
483
  };
440
484
  }
441
485
 
442
486
  static get observers() {
443
- return ['__generatorChanged(_overlayElement, generator, context)'];
487
+ return [
488
+ '__generatorChanged(_overlayElement, generator, context)',
489
+ '__updateSrLabelText(_srLabel, _overlayContent)',
490
+ ];
444
491
  }
445
492
 
446
493
  /**
@@ -518,6 +565,27 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
518
565
  document.body.removeEventListener('vaadin-overlay-open', this.__onOverlayOpen);
519
566
  }
520
567
 
568
+ /** @protected */
569
+ ready() {
570
+ super.ready();
571
+
572
+ this._srLabelController = new SlotController(this, 'sr-label', 'div', {
573
+ initializer: (element) => {
574
+ element.id = this._uniqueId;
575
+ element.setAttribute('role', 'tooltip');
576
+ this._srLabel = element;
577
+ },
578
+ });
579
+ this.addController(this._srLabelController);
580
+ }
581
+
582
+ /** @private */
583
+ __computeAriaTarget(ariaTarget, target) {
584
+ const isElementNode = (el) => el && el.nodeType === Node.ELEMENT_NODE;
585
+ const isAriaTargetSet = Array.isArray(ariaTarget) ? ariaTarget.some(isElementNode) : ariaTarget;
586
+ return isAriaTargetSet ? ariaTarget : target;
587
+ }
588
+
521
589
  /** @private */
522
590
  __computeHorizontalAlign(position) {
523
591
  return ['top-end', 'bottom-end', 'start-top', 'start', 'start-bottom'].includes(position) ? 'end' : 'start';
@@ -551,6 +619,24 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
551
619
  /** @private */
552
620
  __tooltipRenderer(root) {
553
621
  root.textContent = typeof this.generator === 'function' ? this.generator(this.context) : this.text;
622
+
623
+ // Update the sr-only label text content
624
+ this._overlayContent = root.textContent;
625
+ }
626
+
627
+ /** @private */
628
+ __effectiveAriaTargetChanged(ariaTarget, oldAriaTarget) {
629
+ if (oldAriaTarget) {
630
+ [oldAriaTarget].flat().forEach((target) => {
631
+ removeValueFromAttribute(target, 'aria-describedby', this._uniqueId);
632
+ });
633
+ }
634
+
635
+ if (ariaTarget) {
636
+ [ariaTarget].flat().forEach((target) => {
637
+ addValueToAttribute(target, 'aria-describedby', this._uniqueId);
638
+ });
639
+ }
554
640
  }
555
641
 
556
642
  /** @private */
@@ -596,8 +682,6 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
596
682
  oldTarget.removeEventListener('mousedown', this.__onMouseDown);
597
683
 
598
684
  this.__targetVisibilityObserver.unobserve(oldTarget);
599
-
600
- removeValueFromAttribute(oldTarget, 'aria-describedby', this._uniqueId);
601
685
  }
602
686
 
603
687
  if (target) {
@@ -611,8 +695,6 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
611
695
  requestAnimationFrame(() => {
612
696
  this.__targetVisibilityObserver.observe(target);
613
697
  });
614
-
615
- addValueToAttribute(target, 'aria-describedby', this._uniqueId);
616
698
  }
617
699
  }
618
700
 
@@ -703,6 +785,17 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
703
785
  }
704
786
  }
705
787
 
788
+ /** @private */
789
+ __onOverlayMouseEnter() {
790
+ // Retain opened state when moving pointer over the overlay.
791
+ // Closing can start due to an offset between the target and
792
+ // the overlay itself. If that's the case, re-open overlay.
793
+ // See https://github.com/vaadin/web-components/issues/6316
794
+ if (this._stateController.isClosing) {
795
+ this._stateController.open({ immediate: true });
796
+ }
797
+ }
798
+
706
799
  /** @private */
707
800
  __onOverlayMouseLeave(event) {
708
801
  if (event.relatedTarget !== this.target) {
@@ -779,8 +872,15 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
779
872
  this.__oldContext = context;
780
873
  }
781
874
  }
875
+
876
+ /** @private */
877
+ __updateSrLabelText(srLabel, textContent) {
878
+ if (srLabel) {
879
+ srLabel.textContent = textContent;
880
+ }
881
+ }
782
882
  }
783
883
 
784
- customElements.define(Tooltip.is, Tooltip);
884
+ defineCustomElement(Tooltip);
785
885
 
786
886
  export { Tooltip };
package/web-types.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/tooltip",
4
- "version": "24.2.0-alpha9",
4
+ "version": "24.2.0-beta2",
5
5
  "description-markup": "markdown",
6
6
  "contributions": {
7
7
  "html": {
8
8
  "elements": [
9
9
  {
10
10
  "name": "vaadin-tooltip",
11
- "description": "`<vaadin-tooltip>` is a Web Component for creating tooltips.\n\n```html\n<button id=\"confirm\">Confirm</button>\n<vaadin-tooltip text=\"Click to save changes\" for=\"confirm\"></vaadin-tooltip>\n```\n\n### Styling\n\n`<vaadin-tooltip>` uses `<vaadin-tooltip-overlay>` internal\nthemable component as the actual visible overlay.\n\nSee [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha9/#/elements/vaadin-overlay) documentation\nfor `<vaadin-tooltip-overlay>` parts.\n\nThe following state attributes are available for styling:\n\nAttribute | Description\n-----------------|----------------------------------------\n`position` | Reflects the `position` property value.\n\nNote: the `theme` attribute value set on `<vaadin-tooltip>` is\npropagated to the internal `<vaadin-tooltip-overlay>` component.\n\n### Custom CSS Properties\n\nThe following custom CSS properties are available on the `<vaadin-tooltip>` element:\n\nCustom CSS property | Description\n---------------------------------|-------------\n`--vaadin-tooltip-offset-top` | Used as an offset when the tooltip is aligned vertically below the target\n`--vaadin-tooltip-offset-bottom` | Used as an offset when the tooltip is aligned vertically above the target\n`--vaadin-tooltip-offset-start` | Used as an offset when the tooltip is aligned horizontally after the target\n`--vaadin-tooltip-offset-end` | Used as an offset when the tooltip is aligned horizontally before the target\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.",
11
+ "description": "`<vaadin-tooltip>` is a Web Component for creating tooltips.\n\n```html\n<button id=\"confirm\">Confirm</button>\n<vaadin-tooltip text=\"Click to save changes\" for=\"confirm\"></vaadin-tooltip>\n```\n\n### Styling\n\n`<vaadin-tooltip>` uses `<vaadin-tooltip-overlay>` internal\nthemable component as the actual visible overlay.\n\nSee [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-beta2/#/elements/vaadin-overlay) documentation\nfor `<vaadin-tooltip-overlay>` parts.\n\nThe following state attributes are available for styling:\n\nAttribute | Description\n-----------------|----------------------------------------\n`position` | Reflects the `position` property value.\n\nNote: the `theme` attribute value set on `<vaadin-tooltip>` is\npropagated to the internal `<vaadin-tooltip-overlay>` component.\n\n### Custom CSS Properties\n\nThe following custom CSS properties are available on the `<vaadin-tooltip>` element:\n\nCustom CSS property | Description\n---------------------------------|-------------\n`--vaadin-tooltip-offset-top` | Used as an offset when the tooltip is aligned vertically below the target\n`--vaadin-tooltip-offset-bottom` | Used as an offset when the tooltip is aligned vertically above the target\n`--vaadin-tooltip-offset-start` | Used as an offset when the tooltip is aligned horizontally after the target\n`--vaadin-tooltip-offset-end` | Used as an offset when the tooltip is aligned horizontally before the target\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.",
12
12
  "attributes": [
13
13
  {
14
14
  "name": "overlay-class",
@@ -134,6 +134,17 @@
134
134
  ]
135
135
  }
136
136
  },
137
+ {
138
+ "name": "ariaTarget",
139
+ "description": "Element used to link with the `aria-describedby`\nattribute. Supports array of multiple elements.\nWhen not set, defaults to `target`.",
140
+ "value": {
141
+ "type": [
142
+ "Object",
143
+ "null",
144
+ "undefined"
145
+ ]
146
+ }
147
+ },
137
148
  {
138
149
  "name": "context",
139
150
  "description": "Object with properties passed to `generator` and\n`shouldShow` functions for generating tooltip text\nor detecting whether to show the tooltip or not.",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/tooltip",
4
- "version": "24.2.0-alpha9",
4
+ "version": "24.2.0-beta2",
5
5
  "description-markup": "markdown",
6
6
  "framework": "lit",
7
7
  "framework-config": {
@@ -16,7 +16,7 @@
16
16
  "elements": [
17
17
  {
18
18
  "name": "vaadin-tooltip",
19
- "description": "`<vaadin-tooltip>` is a Web Component for creating tooltips.\n\n```html\n<button id=\"confirm\">Confirm</button>\n<vaadin-tooltip text=\"Click to save changes\" for=\"confirm\"></vaadin-tooltip>\n```\n\n### Styling\n\n`<vaadin-tooltip>` uses `<vaadin-tooltip-overlay>` internal\nthemable component as the actual visible overlay.\n\nSee [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-alpha9/#/elements/vaadin-overlay) documentation\nfor `<vaadin-tooltip-overlay>` parts.\n\nThe following state attributes are available for styling:\n\nAttribute | Description\n-----------------|----------------------------------------\n`position` | Reflects the `position` property value.\n\nNote: the `theme` attribute value set on `<vaadin-tooltip>` is\npropagated to the internal `<vaadin-tooltip-overlay>` component.\n\n### Custom CSS Properties\n\nThe following custom CSS properties are available on the `<vaadin-tooltip>` element:\n\nCustom CSS property | Description\n---------------------------------|-------------\n`--vaadin-tooltip-offset-top` | Used as an offset when the tooltip is aligned vertically below the target\n`--vaadin-tooltip-offset-bottom` | Used as an offset when the tooltip is aligned vertically above the target\n`--vaadin-tooltip-offset-start` | Used as an offset when the tooltip is aligned horizontally after the target\n`--vaadin-tooltip-offset-end` | Used as an offset when the tooltip is aligned horizontally before the target\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.",
19
+ "description": "`<vaadin-tooltip>` is a Web Component for creating tooltips.\n\n```html\n<button id=\"confirm\">Confirm</button>\n<vaadin-tooltip text=\"Click to save changes\" for=\"confirm\"></vaadin-tooltip>\n```\n\n### Styling\n\n`<vaadin-tooltip>` uses `<vaadin-tooltip-overlay>` internal\nthemable component as the actual visible overlay.\n\nSee [`<vaadin-overlay>`](https://cdn.vaadin.com/vaadin-web-components/24.2.0-beta2/#/elements/vaadin-overlay) documentation\nfor `<vaadin-tooltip-overlay>` parts.\n\nThe following state attributes are available for styling:\n\nAttribute | Description\n-----------------|----------------------------------------\n`position` | Reflects the `position` property value.\n\nNote: the `theme` attribute value set on `<vaadin-tooltip>` is\npropagated to the internal `<vaadin-tooltip-overlay>` component.\n\n### Custom CSS Properties\n\nThe following custom CSS properties are available on the `<vaadin-tooltip>` element:\n\nCustom CSS property | Description\n---------------------------------|-------------\n`--vaadin-tooltip-offset-top` | Used as an offset when the tooltip is aligned vertically below the target\n`--vaadin-tooltip-offset-bottom` | Used as an offset when the tooltip is aligned vertically above the target\n`--vaadin-tooltip-offset-start` | Used as an offset when the tooltip is aligned horizontally after the target\n`--vaadin-tooltip-offset-end` | Used as an offset when the tooltip is aligned horizontally before the target\n\nSee [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.",
20
20
  "extension": true,
21
21
  "attributes": [
22
22
  {
@@ -40,6 +40,13 @@
40
40
  "kind": "expression"
41
41
  }
42
42
  },
43
+ {
44
+ "name": ".ariaTarget",
45
+ "description": "Element used to link with the `aria-describedby`\nattribute. Supports array of multiple elements.\nWhen not set, defaults to `target`.",
46
+ "value": {
47
+ "kind": "expression"
48
+ }
49
+ },
43
50
  {
44
51
  "name": ".context",
45
52
  "description": "Object with properties passed to `generator` and\n`shouldShow` functions for generating tooltip text\nor detecting whether to show the tooltip or not.",