@limetech/lime-elements 37.15.0 → 37.15.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/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [37.15.1](https://github.com/Lundalogik/lime-elements/compare/v37.15.0...v37.15.1) (2024-04-10)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+
7
+ * **tooltip:** avoid tooltip sometimes getting stuck showing ([1e8e45b](https://github.com/Lundalogik/lime-elements/commit/1e8e45b06bd4c0f91b931005489f84d076b81d1d)), closes [#2898](https://github.com/Lundalogik/lime-elements/issues/2898)
8
+
1
9
  ## [37.15.0](https://github.com/Lundalogik/lime-elements/compare/v37.14.1...v37.15.0) (2024-04-05)
2
10
 
3
11
 
@@ -2008,6 +2008,36 @@ const Portal = class {
2008
2008
  };
2009
2009
  Portal.style = portalCss;
2010
2010
 
2011
+ function getOwnerElement(id, startingPoint) {
2012
+ let element = startingPoint;
2013
+ do {
2014
+ element = element.parentNode;
2015
+ } while (element &&
2016
+ element.nodeType !== Node.DOCUMENT_FRAGMENT_NODE &&
2017
+ element.nodeType !== Node.DOCUMENT_NODE);
2018
+ return element === null || element === void 0 ? void 0 : element.getElementById(id);
2019
+ }
2020
+
2021
+ const DEFAULT_DELAY_FOR_SHOWING = 500;
2022
+ class TooltipTimer {
2023
+ constructor(showCallback, hideCallback, delayForShowing = DEFAULT_DELAY_FOR_SHOWING) {
2024
+ this.timerHandle = null;
2025
+ this.showCallback = showCallback;
2026
+ this.hideCallback = hideCallback;
2027
+ this.delayForShowing = delayForShowing;
2028
+ }
2029
+ showAfterDelay() {
2030
+ if (!this.timerHandle) {
2031
+ this.timerHandle = setTimeout(this.showCallback, this.delayForShowing);
2032
+ }
2033
+ }
2034
+ hide() {
2035
+ clearTimeout(this.timerHandle);
2036
+ this.timerHandle = null;
2037
+ this.hideCallback();
2038
+ }
2039
+ }
2040
+
2011
2041
  const tooltipCss = ":host(limel-tooltip){position:absolute;pointer-events:none}";
2012
2042
 
2013
2043
  const DEFAULT_MAX_LENGTH = 50;
@@ -2015,14 +2045,10 @@ const Tooltip = class {
2015
2045
  constructor(hostRef) {
2016
2046
  index.registerInstance(this, hostRef);
2017
2047
  this.showTooltip = () => {
2018
- const tooltipDelay = 500;
2019
- this.showTooltipTimeoutHandle = window.setTimeout(() => {
2020
- this.open = true;
2021
- }, tooltipDelay);
2048
+ this.tooltipTimer.showAfterDelay();
2022
2049
  };
2023
2050
  this.hideTooltip = () => {
2024
- clearTimeout(this.showTooltipTimeoutHandle);
2025
- this.open = false;
2051
+ this.tooltipTimer.hide();
2026
2052
  };
2027
2053
  this.elementId = undefined;
2028
2054
  this.label = undefined;
@@ -2032,9 +2058,10 @@ const Tooltip = class {
2032
2058
  this.open = undefined;
2033
2059
  this.portalId = randomString.createRandomString();
2034
2060
  this.tooltipId = randomString.createRandomString();
2061
+ this.tooltipTimer = new TooltipTimer(() => (this.open = true), () => (this.open = false));
2035
2062
  }
2036
2063
  connectedCallback() {
2037
- this.ownerElement = this.getOwnerElement();
2064
+ this.ownerElement = getOwnerElement(this.elementId, this.host);
2038
2065
  this.setOwnerAriaLabel();
2039
2066
  this.addListeners();
2040
2067
  }
@@ -2066,15 +2093,6 @@ const Tooltip = class {
2066
2093
  (_c = this.ownerElement) === null || _c === void 0 ? void 0 : _c.removeEventListener('focus', this.showTooltip);
2067
2094
  (_d = this.ownerElement) === null || _d === void 0 ? void 0 : _d.removeEventListener('blur', this.hideTooltip);
2068
2095
  }
2069
- getOwnerElement() {
2070
- let element = this.host;
2071
- do {
2072
- element = element.parentNode;
2073
- } while (element &&
2074
- element.nodeType !== Node.DOCUMENT_FRAGMENT_NODE &&
2075
- element.nodeType !== Node.DOCUMENT_NODE);
2076
- return element === null || element === void 0 ? void 0 : element.getElementById(this.elementId);
2077
- }
2078
2096
  get host() { return index.getElement(this); }
2079
2097
  };
2080
2098
  Tooltip.style = tooltipCss;