@vaadin/tooltip 24.2.0-alpha1 → 24.2.0-alpha10

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-alpha1",
3
+ "version": "24.2.0-alpha10",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -35,21 +35,21 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@polymer/polymer": "^3.0.0",
38
- "@vaadin/a11y-base": "24.2.0-alpha1",
39
- "@vaadin/component-base": "24.2.0-alpha1",
40
- "@vaadin/overlay": "24.2.0-alpha1",
41
- "@vaadin/vaadin-lumo-styles": "24.2.0-alpha1",
42
- "@vaadin/vaadin-material-styles": "24.2.0-alpha1",
43
- "@vaadin/vaadin-themable-mixin": "24.2.0-alpha1"
38
+ "@vaadin/a11y-base": "24.2.0-alpha10",
39
+ "@vaadin/component-base": "24.2.0-alpha10",
40
+ "@vaadin/overlay": "24.2.0-alpha10",
41
+ "@vaadin/vaadin-lumo-styles": "24.2.0-alpha10",
42
+ "@vaadin/vaadin-material-styles": "24.2.0-alpha10",
43
+ "@vaadin/vaadin-themable-mixin": "24.2.0-alpha10"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@esm-bundle/chai": "^4.3.4",
47
- "@vaadin/testing-helpers": "^0.4.2",
47
+ "@vaadin/testing-helpers": "^0.5.0",
48
48
  "sinon": "^13.0.2"
49
49
  },
50
50
  "web-types": [
51
51
  "web-types.json",
52
52
  "web-types.lit.json"
53
53
  ],
54
- "gitHead": "0dbb118320203ab6c0c07450a3e718815367589f"
54
+ "gitHead": "ca16b5f88b00ae05fb6d7c7e9874525048e389f0"
55
55
  }
@@ -3,69 +3,75 @@
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 { Overlay } from '@vaadin/overlay/src/vaadin-overlay.js';
6
+ import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
7
+ import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
8
+ import { OverlayMixin } from '@vaadin/overlay/src/vaadin-overlay-mixin.js';
7
9
  import { PositionMixin } from '@vaadin/overlay/src/vaadin-overlay-position-mixin.js';
8
- import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
10
+ import { overlayStyles } from '@vaadin/overlay/src/vaadin-overlay-styles.js';
11
+ import { css, registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
9
12
 
10
- registerStyles(
11
- 'vaadin-tooltip-overlay',
12
- css`
13
- [part='overlay'] {
14
- max-width: 40ch;
15
- }
13
+ const tooltipOverlayStyles = css`
14
+ :host {
15
+ z-index: 1100;
16
+ }
16
17
 
17
- :host([position^='top'][top-aligned]) [part='overlay'],
18
- :host([position^='bottom'][top-aligned]) [part='overlay'] {
19
- margin-top: var(--vaadin-tooltip-offset-top, 0);
20
- }
18
+ [part='overlay'] {
19
+ max-width: 40ch;
20
+ }
21
21
 
22
- :host([position^='top'][bottom-aligned]) [part='overlay'],
23
- :host([position^='bottom'][bottom-aligned]) [part='overlay'] {
24
- margin-bottom: var(--vaadin-tooltip-offset-bottom, 0);
25
- }
22
+ :host([position^='top'][top-aligned]) [part='overlay'],
23
+ :host([position^='bottom'][top-aligned]) [part='overlay'] {
24
+ margin-top: var(--vaadin-tooltip-offset-top, 0);
25
+ }
26
26
 
27
- :host([position^='start'][start-aligned]) [part='overlay'],
28
- :host([position^='end'][start-aligned]) [part='overlay'] {
29
- margin-inline-start: var(--vaadin-tooltip-offset-start, 0);
30
- }
27
+ :host([position^='top'][bottom-aligned]) [part='overlay'],
28
+ :host([position^='bottom'][bottom-aligned]) [part='overlay'] {
29
+ margin-bottom: var(--vaadin-tooltip-offset-bottom, 0);
30
+ }
31
31
 
32
- :host([position^='start'][end-aligned]) [part='overlay'],
33
- :host([position^='end'][end-aligned]) [part='overlay'] {
34
- margin-inline-end: var(--vaadin-tooltip-offset-end, 0);
35
- }
32
+ :host([position^='start'][start-aligned]) [part='overlay'],
33
+ :host([position^='end'][start-aligned]) [part='overlay'] {
34
+ margin-inline-start: var(--vaadin-tooltip-offset-start, 0);
35
+ }
36
36
 
37
- @media (forced-colors: active) {
38
- [part='overlay'] {
39
- outline: 1px dashed;
40
- }
37
+ :host([position^='start'][end-aligned]) [part='overlay'],
38
+ :host([position^='end'][end-aligned]) [part='overlay'] {
39
+ margin-inline-end: var(--vaadin-tooltip-offset-end, 0);
40
+ }
41
+
42
+ @media (forced-colors: active) {
43
+ [part='overlay'] {
44
+ outline: 1px dashed;
41
45
  }
42
- `,
43
- { moduleId: 'vaadin-tooltip-overlay-styles' },
44
- );
46
+ }
47
+ `;
45
48
 
46
- let memoizedTemplate;
49
+ registerStyles('vaadin-tooltip-overlay', [overlayStyles, tooltipOverlayStyles], {
50
+ moduleId: 'vaadin-tooltip-overlay-styles',
51
+ });
47
52
 
48
53
  /**
49
54
  * An element used internally by `<vaadin-tooltip>`. Not intended to be used separately.
50
55
  *
51
- * @extends Overlay
56
+ * @extends HTMLElement
57
+ * @mixes DirMixin
58
+ * @mixes OverlayMixin
59
+ * @mixes PositionMixin
60
+ * @mixes ThemableMixin
52
61
  * @private
53
62
  */
54
- class TooltipOverlay extends PositionMixin(Overlay) {
63
+ class TooltipOverlay extends PositionMixin(OverlayMixin(DirMixin(ThemableMixin(PolymerElement)))) {
55
64
  static get is() {
56
65
  return 'vaadin-tooltip-overlay';
57
66
  }
58
67
 
59
68
  static get template() {
60
- if (!memoizedTemplate) {
61
- memoizedTemplate = super.template.cloneNode(true);
62
- memoizedTemplate.content.querySelector('[part~="overlay"]').removeAttribute('tabindex');
63
-
64
- // Remove whitespace text nodes around the content slot to allow "white-space: pre"
65
- memoizedTemplate.content.querySelector('[part~="content"]').innerHTML = '<slot></slot>';
66
- }
67
-
68
- return memoizedTemplate;
69
+ return html`
70
+ <div id="backdrop" part="backdrop" hidden></div>
71
+ <div part="overlay" id="overlay">
72
+ <div part="content" id="content"><slot></slot></div>
73
+ </div>
74
+ `;
69
75
  }
70
76
 
71
77
  static get properties() {
@@ -78,6 +78,12 @@ declare class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(
78
78
  */
79
79
  static setDefaultHoverDelay(delay: number): void;
80
80
 
81
+ /**
82
+ * Element used to link with the `aria-describedby`
83
+ * attribute. When not set, defaults to `target`.
84
+ */
85
+ ariaTarget: HTMLElement | undefined;
86
+
81
87
  /**
82
88
  * Object with properties passed to `generator` and
83
89
  * `shouldShow` functions for generating tooltip text
@@ -26,6 +26,18 @@ let warmedUp = false;
26
26
  let warmUpTimeout = null;
27
27
  let cooldownTimeout = null;
28
28
 
29
+ /**
30
+ * Resets the global tooltip warmup and cooldown state.
31
+ * Only for internal use in tests.
32
+ * @private
33
+ */
34
+ export function resetGlobalTooltipState() {
35
+ warmedUp = false;
36
+ clearTimeout(warmUpTimeout);
37
+ clearTimeout(cooldownTimeout);
38
+ closing.clear();
39
+ }
40
+
29
41
  /**
30
42
  * Controller for handling tooltip opened state.
31
43
  */
@@ -57,6 +69,14 @@ class TooltipStateController {
57
69
  return tooltip.hideDelay != null && tooltip.hideDelay > 0 ? tooltip.hideDelay : defaultHideDelay;
58
70
  }
59
71
 
72
+ /**
73
+ * Whether closing is currently in progress.
74
+ * @return {boolean}
75
+ */
76
+ get isClosing() {
77
+ return closing.has(this.host);
78
+ }
79
+
60
80
  /**
61
81
  * Schedule opening the tooltip.
62
82
  * @param {Object} options
@@ -261,6 +281,7 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
261
281
  no-vertical-overlap$="[[__computeNoVerticalOverlap(__effectivePosition)]]"
262
282
  horizontal-align="[[__computeHorizontalAlign(__effectivePosition)]]"
263
283
  vertical-align="[[__computeVerticalAlign(__effectivePosition)]]"
284
+ on-mouseenter="__onOverlayMouseEnter"
264
285
  on-mouseleave="__onOverlayMouseLeave"
265
286
  modeless
266
287
  ></vaadin-tooltip-overlay>
@@ -269,6 +290,14 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
269
290
 
270
291
  static get properties() {
271
292
  return {
293
+ /**
294
+ * Element used to link with the `aria-describedby`
295
+ * attribute. When not set, defaults to `target`.
296
+ */
297
+ ariaTarget: {
298
+ type: Object,
299
+ },
300
+
272
301
  /**
273
302
  * Object with properties passed to `generator` and
274
303
  * `shouldShow` functions for generating tooltip text
@@ -408,6 +437,17 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
408
437
  value: 'bottom',
409
438
  },
410
439
 
440
+ /**
441
+ * Element used to link with the `aria-describedby`
442
+ * attribute. When not set, defaults to `target`.
443
+ * @protected
444
+ */
445
+ _effectiveAriaTarget: {
446
+ type: Object,
447
+ computed: '__computeAriaTarget(ariaTarget, target)',
448
+ observer: '__effectiveAriaTargetChanged',
449
+ },
450
+
411
451
  /** @private */
412
452
  __effectivePosition: {
413
453
  type: String,
@@ -506,6 +546,11 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
506
546
  document.body.removeEventListener('vaadin-overlay-open', this.__onOverlayOpen);
507
547
  }
508
548
 
549
+ /** @private */
550
+ __computeAriaTarget(ariaTarget, target) {
551
+ return ariaTarget || target;
552
+ }
553
+
509
554
  /** @private */
510
555
  __computeHorizontalAlign(position) {
511
556
  return ['top-end', 'bottom-end', 'start-top', 'start', 'start-bottom'].includes(position) ? 'end' : 'start';
@@ -541,6 +586,17 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
541
586
  root.textContent = typeof this.generator === 'function' ? this.generator(this.context) : this.text;
542
587
  }
543
588
 
589
+ /** @private */
590
+ __effectiveAriaTargetChanged(ariaTarget, oldAriaTarget) {
591
+ if (oldAriaTarget) {
592
+ removeValueFromAttribute(oldAriaTarget, 'aria-describedby', this._uniqueId);
593
+ }
594
+
595
+ if (ariaTarget) {
596
+ addValueToAttribute(ariaTarget, 'aria-describedby', this._uniqueId);
597
+ }
598
+ }
599
+
544
600
  /** @private */
545
601
  __autoOpenedChanged(opened, oldOpened) {
546
602
  if (opened) {
@@ -584,8 +640,6 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
584
640
  oldTarget.removeEventListener('mousedown', this.__onMouseDown);
585
641
 
586
642
  this.__targetVisibilityObserver.unobserve(oldTarget);
587
-
588
- removeValueFromAttribute(oldTarget, 'aria-describedby', this._uniqueId);
589
643
  }
590
644
 
591
645
  if (target) {
@@ -599,8 +653,6 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
599
653
  requestAnimationFrame(() => {
600
654
  this.__targetVisibilityObserver.observe(target);
601
655
  });
602
-
603
- addValueToAttribute(target, 'aria-describedby', this._uniqueId);
604
656
  }
605
657
  }
606
658
 
@@ -691,6 +743,17 @@ class Tooltip extends OverlayClassMixin(ThemePropertyMixin(ElementMixin(PolymerE
691
743
  }
692
744
  }
693
745
 
746
+ /** @private */
747
+ __onOverlayMouseEnter() {
748
+ // Retain opened state when moving pointer over the overlay.
749
+ // Closing can start due to an offset between the target and
750
+ // the overlay itself. If that's the case, re-open overlay.
751
+ // See https://github.com/vaadin/web-components/issues/6316
752
+ if (this._stateController.isClosing) {
753
+ this._stateController.open({ immediate: true });
754
+ }
755
+ }
756
+
694
757
  /** @private */
695
758
  __onOverlayMouseLeave(event) {
696
759
  if (event.relatedTarget !== this.target) {
@@ -1,3 +1,2 @@
1
- import '@vaadin/overlay/theme/lumo/vaadin-overlay.js';
2
1
  import './vaadin-tooltip-styles.js';
3
2
  import '../../src/vaadin-tooltip.js';
@@ -1,3 +1,2 @@
1
- import '@vaadin/overlay/theme/material/vaadin-overlay.js';
2
1
  import './vaadin-tooltip-styles.js';
3
2
  import '../../src/vaadin-tooltip.js';
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-alpha1",
4
+ "version": "24.2.0-alpha10",
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-alpha1/#/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-alpha10/#/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. When 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-alpha1",
4
+ "version": "24.2.0-alpha10",
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-alpha1/#/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-alpha10/#/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. When 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.",