@zag-js/tooltip 1.45.0 → 1.47.0

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.
@@ -42,7 +42,6 @@ var import_tooltip2 = require("./tooltip.store.js");
42
42
  function connect(service, normalize) {
43
43
  const { state, context, send, scope, prop, event: _event } = service;
44
44
  const id = prop("id");
45
- const hasAriaLabel = !!prop("aria-label");
46
45
  const open = state.matches("open", "closing");
47
46
  const triggerValue = context.get("triggerValue");
48
47
  const currentPlacement = context.get("currentPlacement");
@@ -126,11 +125,9 @@ function connect(service, normalize) {
126
125
  send({ type: "pointer.move", value, triggerId });
127
126
  },
128
127
  onPointerLeave() {
129
- if (disabled) return;
130
128
  send({ type: "pointer.leave" });
131
129
  },
132
130
  onPointerCancel() {
133
- if (disabled) return;
134
131
  send({ type: "pointer.leave" });
135
132
  }
136
133
  });
@@ -168,8 +165,9 @@ function connect(service, normalize) {
168
165
  hidden: !open,
169
166
  "data-state": open ? "open" : "closed",
170
167
  "data-instant": (0, import_dom_query.dataAttr)(instant),
171
- role: hasAriaLabel ? void 0 : "tooltip",
172
- id: hasAriaLabel ? void 0 : contentId,
168
+ role: "tooltip",
169
+ id: contentId,
170
+ "aria-label": prop("aria-label"),
173
171
  "data-placement": currentPlacement,
174
172
  "data-side": currentPlacementSide,
175
173
  onPointerEnter() {
@@ -8,7 +8,6 @@ import { store } from "./tooltip.store.mjs";
8
8
  function connect(service, normalize) {
9
9
  const { state, context, send, scope, prop, event: _event } = service;
10
10
  const id = prop("id");
11
- const hasAriaLabel = !!prop("aria-label");
12
11
  const open = state.matches("open", "closing");
13
12
  const triggerValue = context.get("triggerValue");
14
13
  const currentPlacement = context.get("currentPlacement");
@@ -92,11 +91,9 @@ function connect(service, normalize) {
92
91
  send({ type: "pointer.move", value, triggerId });
93
92
  },
94
93
  onPointerLeave() {
95
- if (disabled) return;
96
94
  send({ type: "pointer.leave" });
97
95
  },
98
96
  onPointerCancel() {
99
- if (disabled) return;
100
97
  send({ type: "pointer.leave" });
101
98
  }
102
99
  });
@@ -134,8 +131,9 @@ function connect(service, normalize) {
134
131
  hidden: !open,
135
132
  "data-state": open ? "open" : "closed",
136
133
  "data-instant": dataAttr(instant),
137
- role: hasAriaLabel ? void 0 : "tooltip",
138
- id: hasAriaLabel ? void 0 : contentId,
134
+ role: "tooltip",
135
+ id: contentId,
136
+ "aria-label": prop("aria-label"),
139
137
  "data-placement": currentPlacement,
140
138
  "data-side": currentPlacementSide,
141
139
  onPointerEnter() {
@@ -67,6 +67,7 @@ var machine = (0, import_core.createMachine)({
67
67
  };
68
68
  },
69
69
  effects: ["trackFocusVisible", "trackStore"],
70
+ exit: ["clearGlobalId"],
70
71
  context: ({ bindable, prop, scope }) => ({
71
72
  currentPlacement: bindable(() => ({ defaultValue: void 0 })),
72
73
  hasPointerMoveOpened: bindable(() => ({ defaultValue: null })),
@@ -161,6 +162,10 @@ var machine = (0, import_core.createMachine)({
161
162
  }
162
163
  ],
163
164
  "pointer.leave": [
165
+ {
166
+ guard: "isDisabled",
167
+ actions: ["clearPointerMoveOpened"]
168
+ },
164
169
  {
165
170
  guard: "isOpenControlled",
166
171
  // We trigger toggleVisibility manually since the `ctx.open` has not changed yet (at this point)
@@ -202,6 +207,11 @@ var machine = (0, import_core.createMachine)({
202
207
  }
203
208
  ],
204
209
  "pointer.leave": [
210
+ {
211
+ // A controlled tooltip can stay open while disabled
212
+ guard: "isDisabled",
213
+ actions: ["clearPointerMoveOpened"]
214
+ },
205
215
  {
206
216
  guard: "isVisible",
207
217
  target: "closing",
@@ -295,7 +305,8 @@ var machine = (0, import_core.createMachine)({
295
305
  isVisible: ({ prop }) => prop("id") === import_tooltip.store.get("id"),
296
306
  isInteractive: ({ prop }) => !!prop("interactive"),
297
307
  hasPointerMoveOpened: ({ context }) => !!context.get("hasPointerMoveOpened"),
298
- isOpenControlled: ({ prop }) => prop("open") !== void 0
308
+ isOpenControlled: ({ prop }) => prop("open") !== void 0,
309
+ isDisabled: ({ prop }) => !!prop("disabled")
299
310
  },
300
311
  actions: {
301
312
  setGlobalId: ({ prop }) => {
@@ -411,14 +422,19 @@ var machine = (0, import_core.createMachine)({
411
422
  },
412
423
  trackStore: ({ prop, send }) => {
413
424
  let cleanup;
425
+ let cancelled = false;
414
426
  queueMicrotask(() => {
427
+ if (cancelled) return;
415
428
  cleanup = import_tooltip.store.subscribe(() => {
416
429
  if (import_tooltip.store.get("id") !== prop("id")) {
417
430
  send({ type: "close", src: "id.change" });
418
431
  }
419
432
  });
420
433
  });
421
- return () => cleanup?.();
434
+ return () => {
435
+ cancelled = true;
436
+ cleanup?.();
437
+ };
422
438
  },
423
439
  trackEscapeKey: ({ send, prop }) => {
424
440
  if (!prop("closeOnEscape")) return;
@@ -33,6 +33,7 @@ var machine = createMachine({
33
33
  };
34
34
  },
35
35
  effects: ["trackFocusVisible", "trackStore"],
36
+ exit: ["clearGlobalId"],
36
37
  context: ({ bindable, prop, scope }) => ({
37
38
  currentPlacement: bindable(() => ({ defaultValue: void 0 })),
38
39
  hasPointerMoveOpened: bindable(() => ({ defaultValue: null })),
@@ -127,6 +128,10 @@ var machine = createMachine({
127
128
  }
128
129
  ],
129
130
  "pointer.leave": [
131
+ {
132
+ guard: "isDisabled",
133
+ actions: ["clearPointerMoveOpened"]
134
+ },
130
135
  {
131
136
  guard: "isOpenControlled",
132
137
  // We trigger toggleVisibility manually since the `ctx.open` has not changed yet (at this point)
@@ -168,6 +173,11 @@ var machine = createMachine({
168
173
  }
169
174
  ],
170
175
  "pointer.leave": [
176
+ {
177
+ // A controlled tooltip can stay open while disabled
178
+ guard: "isDisabled",
179
+ actions: ["clearPointerMoveOpened"]
180
+ },
171
181
  {
172
182
  guard: "isVisible",
173
183
  target: "closing",
@@ -261,7 +271,8 @@ var machine = createMachine({
261
271
  isVisible: ({ prop }) => prop("id") === store.get("id"),
262
272
  isInteractive: ({ prop }) => !!prop("interactive"),
263
273
  hasPointerMoveOpened: ({ context }) => !!context.get("hasPointerMoveOpened"),
264
- isOpenControlled: ({ prop }) => prop("open") !== void 0
274
+ isOpenControlled: ({ prop }) => prop("open") !== void 0,
275
+ isDisabled: ({ prop }) => !!prop("disabled")
265
276
  },
266
277
  actions: {
267
278
  setGlobalId: ({ prop }) => {
@@ -377,14 +388,19 @@ var machine = createMachine({
377
388
  },
378
389
  trackStore: ({ prop, send }) => {
379
390
  let cleanup;
391
+ let cancelled = false;
380
392
  queueMicrotask(() => {
393
+ if (cancelled) return;
381
394
  cleanup = store.subscribe(() => {
382
395
  if (store.get("id") !== prop("id")) {
383
396
  send({ type: "close", src: "id.change" });
384
397
  }
385
398
  });
386
399
  });
387
- return () => cleanup?.();
400
+ return () => {
401
+ cancelled = true;
402
+ cleanup?.();
403
+ };
388
404
  },
389
405
  trackEscapeKey: ({ send, prop }) => {
390
406
  if (!prop("closeOnEscape")) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tooltip",
3
- "version": "1.45.0",
3
+ "version": "1.47.0",
4
4
  "description": "Core logic for the tooltip widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,13 +29,13 @@
29
29
  "url": "https://github.com/chakra-ui/zag/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@zag-js/anatomy": "1.45.0",
33
- "@zag-js/core": "1.45.0",
34
- "@zag-js/popper": "1.45.0",
35
- "@zag-js/focus-visible": "1.45.0",
36
- "@zag-js/dom-query": "1.45.0",
37
- "@zag-js/utils": "1.45.0",
38
- "@zag-js/types": "1.45.0"
32
+ "@zag-js/anatomy": "1.47.0",
33
+ "@zag-js/core": "1.47.0",
34
+ "@zag-js/popper": "1.47.0",
35
+ "@zag-js/focus-visible": "1.47.0",
36
+ "@zag-js/dom-query": "1.47.0",
37
+ "@zag-js/utils": "1.47.0",
38
+ "@zag-js/types": "1.47.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "clean-package": "2.2.0"