@zag-js/tooltip 1.46.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() {
@@ -162,6 +162,10 @@ var machine = (0, import_core.createMachine)({
162
162
  }
163
163
  ],
164
164
  "pointer.leave": [
165
+ {
166
+ guard: "isDisabled",
167
+ actions: ["clearPointerMoveOpened"]
168
+ },
165
169
  {
166
170
  guard: "isOpenControlled",
167
171
  // We trigger toggleVisibility manually since the `ctx.open` has not changed yet (at this point)
@@ -203,6 +207,11 @@ var machine = (0, import_core.createMachine)({
203
207
  }
204
208
  ],
205
209
  "pointer.leave": [
210
+ {
211
+ // A controlled tooltip can stay open while disabled
212
+ guard: "isDisabled",
213
+ actions: ["clearPointerMoveOpened"]
214
+ },
206
215
  {
207
216
  guard: "isVisible",
208
217
  target: "closing",
@@ -296,7 +305,8 @@ var machine = (0, import_core.createMachine)({
296
305
  isVisible: ({ prop }) => prop("id") === import_tooltip.store.get("id"),
297
306
  isInteractive: ({ prop }) => !!prop("interactive"),
298
307
  hasPointerMoveOpened: ({ context }) => !!context.get("hasPointerMoveOpened"),
299
- isOpenControlled: ({ prop }) => prop("open") !== void 0
308
+ isOpenControlled: ({ prop }) => prop("open") !== void 0,
309
+ isDisabled: ({ prop }) => !!prop("disabled")
300
310
  },
301
311
  actions: {
302
312
  setGlobalId: ({ prop }) => {
@@ -412,14 +422,19 @@ var machine = (0, import_core.createMachine)({
412
422
  },
413
423
  trackStore: ({ prop, send }) => {
414
424
  let cleanup;
425
+ let cancelled = false;
415
426
  queueMicrotask(() => {
427
+ if (cancelled) return;
416
428
  cleanup = import_tooltip.store.subscribe(() => {
417
429
  if (import_tooltip.store.get("id") !== prop("id")) {
418
430
  send({ type: "close", src: "id.change" });
419
431
  }
420
432
  });
421
433
  });
422
- return () => cleanup?.();
434
+ return () => {
435
+ cancelled = true;
436
+ cleanup?.();
437
+ };
423
438
  },
424
439
  trackEscapeKey: ({ send, prop }) => {
425
440
  if (!prop("closeOnEscape")) return;
@@ -128,6 +128,10 @@ var machine = createMachine({
128
128
  }
129
129
  ],
130
130
  "pointer.leave": [
131
+ {
132
+ guard: "isDisabled",
133
+ actions: ["clearPointerMoveOpened"]
134
+ },
131
135
  {
132
136
  guard: "isOpenControlled",
133
137
  // We trigger toggleVisibility manually since the `ctx.open` has not changed yet (at this point)
@@ -169,6 +173,11 @@ var machine = createMachine({
169
173
  }
170
174
  ],
171
175
  "pointer.leave": [
176
+ {
177
+ // A controlled tooltip can stay open while disabled
178
+ guard: "isDisabled",
179
+ actions: ["clearPointerMoveOpened"]
180
+ },
172
181
  {
173
182
  guard: "isVisible",
174
183
  target: "closing",
@@ -262,7 +271,8 @@ var machine = createMachine({
262
271
  isVisible: ({ prop }) => prop("id") === store.get("id"),
263
272
  isInteractive: ({ prop }) => !!prop("interactive"),
264
273
  hasPointerMoveOpened: ({ context }) => !!context.get("hasPointerMoveOpened"),
265
- isOpenControlled: ({ prop }) => prop("open") !== void 0
274
+ isOpenControlled: ({ prop }) => prop("open") !== void 0,
275
+ isDisabled: ({ prop }) => !!prop("disabled")
266
276
  },
267
277
  actions: {
268
278
  setGlobalId: ({ prop }) => {
@@ -378,14 +388,19 @@ var machine = createMachine({
378
388
  },
379
389
  trackStore: ({ prop, send }) => {
380
390
  let cleanup;
391
+ let cancelled = false;
381
392
  queueMicrotask(() => {
393
+ if (cancelled) return;
382
394
  cleanup = store.subscribe(() => {
383
395
  if (store.get("id") !== prop("id")) {
384
396
  send({ type: "close", src: "id.change" });
385
397
  }
386
398
  });
387
399
  });
388
- return () => cleanup?.();
400
+ return () => {
401
+ cancelled = true;
402
+ cleanup?.();
403
+ };
389
404
  },
390
405
  trackEscapeKey: ({ send, prop }) => {
391
406
  if (!prop("closeOnEscape")) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tooltip",
3
- "version": "1.46.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.46.0",
33
- "@zag-js/core": "1.46.0",
34
- "@zag-js/popper": "1.46.0",
35
- "@zag-js/focus-visible": "1.46.0",
36
- "@zag-js/dom-query": "1.46.0",
37
- "@zag-js/utils": "1.46.0",
38
- "@zag-js/types": "1.46.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"