@vaadin/tooltip 23.3.0-alpha1 → 23.3.0-alpha2

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": "23.3.0-alpha1",
3
+ "version": "23.3.0-alpha2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -35,11 +35,11 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@polymer/polymer": "^3.0.0",
38
- "@vaadin/component-base": "23.3.0-alpha1",
39
- "@vaadin/vaadin-lumo-styles": "23.3.0-alpha1",
40
- "@vaadin/vaadin-material-styles": "23.3.0-alpha1",
41
- "@vaadin/vaadin-overlay": "23.3.0-alpha1",
42
- "@vaadin/vaadin-themable-mixin": "23.3.0-alpha1"
38
+ "@vaadin/component-base": "23.3.0-alpha2",
39
+ "@vaadin/vaadin-lumo-styles": "23.3.0-alpha2",
40
+ "@vaadin/vaadin-material-styles": "23.3.0-alpha2",
41
+ "@vaadin/vaadin-overlay": "23.3.0-alpha2",
42
+ "@vaadin/vaadin-themable-mixin": "23.3.0-alpha2"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@esm-bundle/chai": "^4.3.4",
@@ -50,5 +50,5 @@
50
50
  "web-types.json",
51
51
  "web-types.lit.json"
52
52
  ],
53
- "gitHead": "beabc527d4b1274eb798ff701d406fed45cfe638"
53
+ "gitHead": "ae61027c62ffa7f7d70cfc50e43f333addfc74b6"
54
54
  }
@@ -64,6 +64,17 @@ class TooltipOverlay extends PositionMixin(OverlayElement) {
64
64
  };
65
65
  }
66
66
 
67
+ /** @protected */
68
+ ready() {
69
+ super.ready();
70
+
71
+ // When setting `manual` and `opened` attributes, the overlay is already moved to body
72
+ // by the time when `ready()` callback of the `vaadin-tooltip` is executed by Polymer,
73
+ // so querySelector() would return null. So we use this workaround to set properties.
74
+ this.owner = this.__dataHost;
75
+ this.owner._overlayElement = this;
76
+ }
77
+
67
78
  requestContentUpdate() {
68
79
  super.requestContentUpdate();
69
80
 
@@ -78,8 +78,9 @@ declare class Tooltip extends ThemePropertyMixin(ElementMixin(HTMLElement)) {
78
78
  static setDefaultHoverDelay(delay: number): void;
79
79
 
80
80
  /**
81
- * Object with properties passed to `textGenerator`
82
- * function to be used for generating tooltip text.
81
+ * Object with properties passed to `generator` and
82
+ * `shouldShow` functions for generating tooltip text
83
+ * or detecting whether to show the tooltip or not.
83
84
  */
84
85
  context: Record<string, unknown>;
85
86
 
@@ -135,10 +136,11 @@ declare class Tooltip extends ThemePropertyMixin(ElementMixin(HTMLElement)) {
135
136
  /**
136
137
  * Function used to detect whether to show the tooltip based on a condition,
137
138
  * called every time the tooltip is about to be shown on hover and focus.
138
- * The function accepts a reference to the target element as a parameter.
139
+ * The function takes two parameters: `target` and `context`, which contain
140
+ * values of the corresponding tooltip properties at the time of calling.
139
141
  * The tooltip is only shown when the function invocation returns `true`.
140
142
  */
141
- shouldShow: (target: HTMLElement) => boolean;
143
+ shouldShow: (target: HTMLElement, context?: Record<string, unknown>) => boolean;
142
144
 
143
145
  /**
144
146
  * Reference to the element used as a tooltip trigger.
@@ -158,7 +160,7 @@ declare class Tooltip extends ThemePropertyMixin(ElementMixin(HTMLElement)) {
158
160
  * Use the `context` property to provide argument
159
161
  * that can be passed to the generator function.
160
162
  */
161
- textGenerator: (context: Record<string, unknown>) => string;
163
+ generator: (context: Record<string, unknown>) => string;
162
164
  }
163
165
 
164
166
  declare global {
@@ -89,6 +89,7 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
89
89
  no-vertical-overlap$="[[__computeNoVerticalOverlap(position)]]"
90
90
  horizontal-align="[[__computeHorizontalAlign(position)]]"
91
91
  vertical-align="[[__computeVerticalAlign(position)]]"
92
+ on-mouseleave="__onOverlayMouseLeave"
92
93
  modeless
93
94
  ></vaadin-tooltip-overlay>
94
95
  `;
@@ -97,8 +98,9 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
97
98
  static get properties() {
98
99
  return {
99
100
  /**
100
- * Object with properties passed to `textGenerator`
101
- * function to be used for generating tooltip text.
101
+ * Object with properties passed to `generator` and
102
+ * `shouldShow` functions for generating tooltip text
103
+ * or detecting whether to show the tooltip or not.
102
104
  */
103
105
  context: {
104
106
  type: Object,
@@ -177,13 +179,14 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
177
179
  /**
178
180
  * Function used to detect whether to show the tooltip based on a condition,
179
181
  * called every time the tooltip is about to be shown on hover and focus.
180
- * The function accepts a reference to the target element as a parameter.
182
+ * The function takes two parameters: `target` and `context`, which contain
183
+ * values of the corresponding tooltip properties at the time of calling.
181
184
  * The tooltip is only shown when the function invocation returns `true`.
182
185
  */
183
186
  shouldShow: {
184
187
  type: Object,
185
188
  value: () => {
186
- return (_target) => true;
189
+ return (_target, _context) => true;
187
190
  },
188
191
  },
189
192
 
@@ -211,7 +214,7 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
211
214
  * Use the `context` property to provide argument
212
215
  * that can be passed to the generator function.
213
216
  */
214
- textGenerator: {
217
+ generator: {
215
218
  type: Object,
216
219
  },
217
220
 
@@ -237,7 +240,7 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
237
240
  }
238
241
 
239
242
  static get observers() {
240
- return ['__textGeneratorChanged(_overlayElement, textGenerator, context)'];
243
+ return ['__generatorChanged(_overlayElement, generator, context)'];
241
244
  }
242
245
 
243
246
  /**
@@ -291,14 +294,6 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
291
294
  );
292
295
  }
293
296
 
294
- /** @protected */
295
- ready() {
296
- super.ready();
297
-
298
- this._overlayElement = this.shadowRoot.querySelector('vaadin-tooltip-overlay');
299
- this._overlayElement.owner = this;
300
- }
301
-
302
297
  /** @protected */
303
298
  disconnectedCallback() {
304
299
  super.disconnectedCallback();
@@ -335,7 +330,7 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
335
330
 
336
331
  /** @private */
337
332
  __tooltipRenderer(root) {
338
- root.textContent = typeof this.textGenerator === 'function' ? this.textGenerator(this.context) : this.text;
333
+ root.textContent = typeof this.generator === 'function' ? this.generator(this.context) : this.text;
339
334
  }
340
335
 
341
336
  /** @private */
@@ -381,7 +376,10 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
381
376
  target.addEventListener('focusout', this.__onFocusout);
382
377
  target.addEventListener('mousedown', this.__onMouseDown);
383
378
 
384
- this.__targetVisibilityObserver.observe(target);
379
+ // Wait before observing to avoid Chrome issue.
380
+ requestAnimationFrame(() => {
381
+ this.__targetVisibilityObserver.observe(target);
382
+ });
385
383
 
386
384
  addValueToAttribute(target, 'aria-describedby', this._uniqueId);
387
385
  }
@@ -389,6 +387,10 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
389
387
 
390
388
  /** @private */
391
389
  __onFocusin(event) {
390
+ if (this.manual) {
391
+ return;
392
+ }
393
+
392
394
  // Only open on keyboard focus.
393
395
  if (!isKeyboardActive()) {
394
396
  return;
@@ -399,7 +401,7 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
399
401
  return;
400
402
  }
401
403
 
402
- if (typeof this.shouldShow === 'function' && this.shouldShow(this.target) !== true) {
404
+ if (!this.__isShouldShow()) {
403
405
  return;
404
406
  }
405
407
 
@@ -412,6 +414,10 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
412
414
 
413
415
  /** @private */
414
416
  __onFocusout(event) {
417
+ if (this.manual) {
418
+ return;
419
+ }
420
+
415
421
  // Do not close when moving focus within a component.
416
422
  if (this.target.contains(event.relatedTarget)) {
417
423
  return;
@@ -439,7 +445,11 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
439
445
 
440
446
  /** @private */
441
447
  __onMouseEnter() {
442
- if (typeof this.shouldShow === 'function' && this.shouldShow(this.target) !== true) {
448
+ if (this.manual) {
449
+ return;
450
+ }
451
+
452
+ if (!this.__isShouldShow()) {
443
453
  return;
444
454
  }
445
455
 
@@ -456,7 +466,25 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
456
466
  }
457
467
 
458
468
  /** @private */
459
- __onMouseLeave() {
469
+ __onMouseLeave(event) {
470
+ if (event.relatedTarget !== this._overlayElement) {
471
+ this.__handleMouseLeave();
472
+ }
473
+ }
474
+
475
+ /** @private */
476
+ __onOverlayMouseLeave(event) {
477
+ if (event.relatedTarget !== this.target) {
478
+ this.__handleMouseLeave();
479
+ }
480
+ }
481
+
482
+ /** @private */
483
+ __handleMouseLeave() {
484
+ if (this.manual) {
485
+ return;
486
+ }
487
+
460
488
  this.__hoverInside = false;
461
489
 
462
490
  if (!this.__focusInside) {
@@ -481,6 +509,15 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
481
509
  }
482
510
  }
483
511
 
512
+ /** @private */
513
+ __isShouldShow() {
514
+ if (typeof this.shouldShow === 'function' && this.shouldShow(this.target, this.context) !== true) {
515
+ return false;
516
+ }
517
+
518
+ return true;
519
+ }
520
+
484
521
  /**
485
522
  * Schedule opening the tooltip.
486
523
  * @param {boolean} immediate
@@ -632,13 +669,13 @@ class Tooltip extends ThemePropertyMixin(ElementMixin(PolymerElement)) {
632
669
  }
633
670
 
634
671
  /** @private */
635
- __textGeneratorChanged(overlayElement, textGenerator, context) {
672
+ __generatorChanged(overlayElement, generator, context) {
636
673
  if (overlayElement) {
637
- if (textGenerator !== this.__oldTextGenerator || context !== this.__oldContext) {
674
+ if (generator !== this.__oldTextGenerator || context !== this.__oldContext) {
638
675
  overlayElement.requestContentUpdate();
639
676
  }
640
677
 
641
- this.__oldTextGenerator = textGenerator;
678
+ this.__oldTextGenerator = generator;
642
679
  this.__oldContext = context;
643
680
  }
644
681
  }
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": "23.3.0-alpha1",
4
+ "version": "23.3.0-alpha2",
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/23.3.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/custom-theme/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/23.3.0-alpha2/#/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/custom-theme/styling-components) documentation.",
12
12
  "attributes": [
13
13
  {
14
14
  "name": "focus-delay",
@@ -114,7 +114,7 @@
114
114
  "properties": [
115
115
  {
116
116
  "name": "context",
117
- "description": "Object with properties passed to `textGenerator`\nfunction to be used for generating tooltip text.",
117
+ "description": "Object with properties passed to `generator` and\n`shouldShow` functions for generating tooltip text\nor detecting whether to show the tooltip or not.",
118
118
  "value": {
119
119
  "type": [
120
120
  "Object",
@@ -202,7 +202,7 @@
202
202
  },
203
203
  {
204
204
  "name": "shouldShow",
205
- "description": "Function used to detect whether to show the tooltip based on a condition,\ncalled every time the tooltip is about to be shown on hover and focus.\nThe function accepts a reference to the target element as a parameter.\nThe tooltip is only shown when the function invocation returns `true`.",
205
+ "description": "Function used to detect whether to show the tooltip based on a condition,\ncalled every time the tooltip is about to be shown on hover and focus.\nThe function takes two parameters: `target` and `context`, which contain\nvalues of the corresponding tooltip properties at the time of calling.\nThe tooltip is only shown when the function invocation returns `true`.",
206
206
  "value": {
207
207
  "type": [
208
208
  "Object",
@@ -234,7 +234,7 @@
234
234
  }
235
235
  },
236
236
  {
237
- "name": "textGenerator",
237
+ "name": "generator",
238
238
  "description": "Function used to generate the tooltip content.\nWhen provided, it overrides the `text` property.\nUse the `context` property to provide argument\nthat can be passed to the generator function.",
239
239
  "value": {
240
240
  "type": [
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/web-types",
3
3
  "name": "@vaadin/tooltip",
4
- "version": "23.3.0-alpha1",
4
+ "version": "23.3.0-alpha2",
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/23.3.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/custom-theme/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/23.3.0-alpha2/#/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/custom-theme/styling-components) documentation.",
20
20
  "extension": true,
21
21
  "attributes": [
22
22
  {
@@ -35,7 +35,7 @@
35
35
  },
36
36
  {
37
37
  "name": ".context",
38
- "description": "Object with properties passed to `textGenerator`\nfunction to be used for generating tooltip text.",
38
+ "description": "Object with properties passed to `generator` and\n`shouldShow` functions for generating tooltip text\nor detecting whether to show the tooltip or not.",
39
39
  "value": {
40
40
  "kind": "expression"
41
41
  }
@@ -77,7 +77,7 @@
77
77
  },
78
78
  {
79
79
  "name": ".shouldShow",
80
- "description": "Function used to detect whether to show the tooltip based on a condition,\ncalled every time the tooltip is about to be shown on hover and focus.\nThe function accepts a reference to the target element as a parameter.\nThe tooltip is only shown when the function invocation returns `true`.",
80
+ "description": "Function used to detect whether to show the tooltip based on a condition,\ncalled every time the tooltip is about to be shown on hover and focus.\nThe function takes two parameters: `target` and `context`, which contain\nvalues of the corresponding tooltip properties at the time of calling.\nThe tooltip is only shown when the function invocation returns `true`.",
81
81
  "value": {
82
82
  "kind": "expression"
83
83
  }
@@ -97,7 +97,7 @@
97
97
  }
98
98
  },
99
99
  {
100
- "name": ".textGenerator",
100
+ "name": ".generator",
101
101
  "description": "Function used to generate the tooltip content.\nWhen provided, it overrides the `text` property.\nUse the `context` property to provide argument\nthat can be passed to the generator function.",
102
102
  "value": {
103
103
  "kind": "expression"