@aquera/nile-elements 1.2.8-beta-1.8 → 1.2.8-beta-1.9

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
@@ -3,7 +3,7 @@
3
3
  "description": "Webcomponent nile-elements following open-wc recommendations",
4
4
  "license": "MIT",
5
5
  "author": "nile-elements",
6
- "version": "1.2.8-beta-1.8",
6
+ "version": "1.2.8-beta-1.9",
7
7
  "main": "dist/src/index.js",
8
8
  "type": "module",
9
9
  "module": "dist/src/index.js",
@@ -186,52 +186,79 @@ export class NileliteTooltip extends NileElement {
186
186
  return undefined;
187
187
  },
188
188
  };
189
-
190
- let targets: HTMLElement[] = [];
191
-
192
189
  if (this.for) {
193
- const selector = this.for.trim();
194
- try {
195
- targets = Array.from(document.querySelectorAll(selector));
196
- } catch {
197
- targets = Array.from(document.querySelectorAll(`.${this.for}`));
198
- }
199
-
200
- if (targets.length > 0) {
201
-
202
- this.tooltipInstances = targets.map(el => {
203
- const instance = tippy(el as HTMLElement, {
204
- ...options,
205
- content: el.getAttribute('content') || this.content,
190
+ if (this.singleton && !this.for.startsWith('#') && !document.getElementById(this.for)) {
191
+ const targetEls = Array.from(document.querySelectorAll(`.${this.for}`));
192
+ if (targetEls.length > 0) {
193
+ this.tooltipInstances = targetEls.map(el => {
194
+ const instance = tippy(el as HTMLElement, {
195
+ ...options,
196
+ content: el.getAttribute('content') || this.content,
197
+ });
198
+ instance.popper.querySelector('.tippy-box')?.classList.add(this.size);
199
+ return instance;
206
200
  });
207
- instance.popper.querySelector('.tippy-box')?.classList.add(this.size);
208
- return instance;
209
- });
210
-
211
- if (this.singleton && this.tooltipInstances.length > 1) {
201
+
212
202
  this.singletonInstance = createSingleton(this.tooltipInstances, {
213
203
  delay: [75, 0],
214
204
  arrow: roundArrow,
215
205
  moveTransition: 'transform 0.15s ease-out',
216
206
  });
207
+
208
+ if (this.open) queueMicrotask(() => this.singletonInstance?.show());
209
+ return;
217
210
  }
218
-
219
- if (this.open) {
220
- queueMicrotask(() => {
221
- this.singletonInstance?.show();
222
- this.tooltipInstances?.forEach(t => t.show());
211
+ }
212
+
213
+ const containerEl = document.getElementById(this.for);
214
+ if (this.singleton && containerEl) {
215
+ const childEls = Array.from(containerEl.querySelectorAll('[content]'));
216
+ if (childEls.length > 0) {
217
+ this.tooltipInstances = childEls.map(el => {
218
+ const instance = tippy(el as HTMLElement, {
219
+ ...options,
220
+ content: el.getAttribute('content') || this.content,
221
+ });
222
+ instance.popper.querySelector('.tippy-box')?.classList.add(this.size);
223
+ return instance;
223
224
  });
225
+
226
+ this.singletonInstance = createSingleton(this.tooltipInstances, {
227
+ delay: [75, 0],
228
+ arrow: roundArrow,
229
+ moveTransition: 'transform 0.15s ease-out',
230
+ });
231
+
232
+ if (this.open) queueMicrotask(() => this.singletonInstance?.show());
233
+ return;
224
234
  }
225
- return;
226
235
  }
227
-
228
- const targetEl = document.getElementById(this.for);
229
- if (targetEl) {
230
- this.singleInstance = tippy(targetEl, options);
231
- this.singleInstance.popper.querySelector('.tippy-box')?.classList.add(this.size);
232
- if (this.open) queueMicrotask(() => this.singleInstance?.show());
233
- return;
236
+
237
+ this.targetEl = document.getElementById(this.for);
238
+ if (!this.targetEl) return;
239
+
240
+ if (!this.id) {
241
+ this.generatedId = `nile-tooltip-${Math.random()
242
+ .toString(36)
243
+ .slice(2, 9)}`;
244
+ this.id = this.generatedId;
234
245
  }
246
+
247
+ this.prevDescribedby = this.targetEl.getAttribute('aria-describedby');
248
+ const describedby = this.prevDescribedby
249
+ ? `${this.prevDescribedby} ${this.id}`
250
+ : this.id;
251
+ this.targetEl.setAttribute('aria-describedby', describedby);
252
+
253
+ this.singleInstance = tippy(this.targetEl, options);
254
+ if (this.size)
255
+ this.singleInstance.popper
256
+ .querySelector('.tippy-box')
257
+ ?.classList.add(this.size);
258
+ if (this.open) {
259
+ queueMicrotask(() => this.singleInstance?.show());
260
+ }
261
+ return;
235
262
  }
236
263
 
237
264
  const children = Array.from(this.querySelectorAll('*'));
@@ -253,10 +280,8 @@ export class NileliteTooltip extends NileElement {
253
280
  }
254
281
 
255
282
  if (this.open) {
256
- queueMicrotask(() => {
257
- this.singletonInstance?.show();
258
- this.tooltipInstances?.forEach(t => t.show());
259
- });
283
+ if (this.singletonInstance) this.singletonInstance.show();
284
+ else this.tooltipInstances.forEach(t => t.show());
260
285
  }
261
286
  }
262
287
  }