@zag-js/tabs 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.
package/dist/index.d.mts CHANGED
@@ -6,3 +6,4 @@ export { TabsApi as Api, ContentProps, ElementIds, FocusChangeDetails, IntlTrans
6
6
  import '@zag-js/anatomy';
7
7
  import '@zag-js/core';
8
8
  import '@zag-js/types';
9
+ import '@zag-js/dom-query';
package/dist/index.d.ts CHANGED
@@ -6,3 +6,4 @@ export { TabsApi as Api, ContentProps, ElementIds, FocusChangeDetails, IntlTrans
6
6
  import '@zag-js/anatomy';
7
7
  import '@zag-js/core';
8
8
  import '@zag-js/types';
9
+ import '@zag-js/dom-query';
@@ -1,6 +1,7 @@
1
1
  import { Service } from '@zag-js/core';
2
2
  import { PropTypes, NormalizeProps } from '@zag-js/types';
3
3
  import { TabsSchema, TabsApi } from './tabs.types.mjs';
4
+ import '@zag-js/dom-query';
4
5
 
5
6
  declare function connect<T extends PropTypes>(service: Service<TabsSchema>, normalize: NormalizeProps<T>): TabsApi<T>;
6
7
 
@@ -1,6 +1,7 @@
1
1
  import { Service } from '@zag-js/core';
2
2
  import { PropTypes, NormalizeProps } from '@zag-js/types';
3
3
  import { TabsSchema, TabsApi } from './tabs.types.js';
4
+ import '@zag-js/dom-query';
4
5
 
5
6
  declare function connect<T extends PropTypes>(service: Service<TabsSchema>, normalize: NormalizeProps<T>): TabsApi<T>;
6
7
 
@@ -1,5 +1,6 @@
1
1
  import * as _zag_js_core from '@zag-js/core';
2
2
  import { TabsSchema } from './tabs.types.mjs';
3
+ import '@zag-js/dom-query';
3
4
  import '@zag-js/types';
4
5
 
5
6
  declare const machine: _zag_js_core.Machine<TabsSchema>;
@@ -1,5 +1,6 @@
1
1
  import * as _zag_js_core from '@zag-js/core';
2
2
  import { TabsSchema } from './tabs.types.js';
3
+ import '@zag-js/dom-query';
3
4
  import '@zag-js/types';
4
5
 
5
6
  declare const machine: _zag_js_core.Machine<TabsSchema>;
@@ -81,7 +81,8 @@ var machine = createMachine({
81
81
  refs() {
82
82
  return {
83
83
  indicatorCleanup: null,
84
- prevValue: null
84
+ prevValue: null,
85
+ focusFrame: import_dom_query.AnimationFrame.create()
85
86
  };
86
87
  },
87
88
  watch({ context, prop, track, action }) {
@@ -110,7 +111,7 @@ var machine = createMachine({
110
111
  }
111
112
  },
112
113
  entry: ["syncPrevValue", "syncIndicatorRect", "syncTabIndex", "syncSsr"],
113
- exit: ["cleanupObserver"],
114
+ exit: ["cleanupObserver", "cancelFocusFrame"],
114
115
  states: {
115
116
  idle: {
116
117
  on: {
@@ -125,6 +126,7 @@ var machine = createMachine({
125
126
  }
126
127
  },
127
128
  focused: {
129
+ exit: ["cancelFocusFrame"],
128
130
  on: {
129
131
  TAB_CLICK: {
130
132
  actions: ["setFocusedValue", "setValue", "requestNavigation"]
@@ -213,24 +215,24 @@ var machine = createMachine({
213
215
  clearValue({ context }) {
214
216
  context.set("value", null);
215
217
  },
216
- focusFirstTab({ scope }) {
217
- (0, import_dom_query.raf)(() => {
218
+ focusFirstTab({ scope, refs }) {
219
+ refs.get("focusFrame").request(() => {
218
220
  dom.getFirstTriggerEl(scope)?.focus();
219
221
  });
220
222
  },
221
- focusLastTab({ scope }) {
222
- (0, import_dom_query.raf)(() => {
223
+ focusLastTab({ scope, refs }) {
224
+ refs.get("focusFrame").request(() => {
223
225
  dom.getLastTriggerEl(scope)?.focus();
224
226
  });
225
227
  },
226
- focusNextTab({ context, prop, scope, event }) {
228
+ focusNextTab({ context, prop, scope, event, refs }) {
227
229
  const focusedValue = event.value ?? context.get("focusedValue");
228
230
  if (!focusedValue) return;
229
231
  const triggerEl = dom.getNextTriggerEl(scope, {
230
232
  value: focusedValue,
231
233
  loopFocus: prop("loopFocus")
232
234
  });
233
- (0, import_dom_query.raf)(() => {
235
+ refs.get("focusFrame").request(() => {
234
236
  if (prop("composite")) {
235
237
  triggerEl?.focus();
236
238
  } else if (triggerEl?.dataset.value != null) {
@@ -238,14 +240,14 @@ var machine = createMachine({
238
240
  }
239
241
  });
240
242
  },
241
- focusPrevTab({ context, prop, scope, event }) {
243
+ focusPrevTab({ context, prop, scope, event, refs }) {
242
244
  const focusedValue = event.value ?? context.get("focusedValue");
243
245
  if (!focusedValue) return;
244
246
  const triggerEl = dom.getPrevTriggerEl(scope, {
245
247
  value: focusedValue,
246
248
  loopFocus: prop("loopFocus")
247
249
  });
248
- (0, import_dom_query.raf)(() => {
250
+ refs.get("focusFrame").request(() => {
249
251
  if (prop("composite")) {
250
252
  triggerEl?.focus();
251
253
  } else if (triggerEl?.dataset.value != null) {
@@ -267,6 +269,9 @@ var machine = createMachine({
267
269
  }
268
270
  });
269
271
  },
272
+ cancelFocusFrame({ refs }) {
273
+ refs.get("focusFrame").cancel();
274
+ },
270
275
  cleanupObserver({ refs }) {
271
276
  const cleanup = refs.get("indicatorCleanup");
272
277
  if (cleanup) cleanup();
@@ -1,6 +1,6 @@
1
1
  // src/tabs.machine.ts
2
2
  import { setup } from "@zag-js/core";
3
- import { getFocusables, isAnchorElement, raf, resizeObserverBorderBox } from "@zag-js/dom-query";
3
+ import { AnimationFrame, getFocusables, isAnchorElement, raf, resizeObserverBorderBox } from "@zag-js/dom-query";
4
4
  import { callAll, isEqual } from "@zag-js/utils";
5
5
  import * as dom from "./tabs.dom.mjs";
6
6
  var { createMachine } = setup();
@@ -47,7 +47,8 @@ var machine = createMachine({
47
47
  refs() {
48
48
  return {
49
49
  indicatorCleanup: null,
50
- prevValue: null
50
+ prevValue: null,
51
+ focusFrame: AnimationFrame.create()
51
52
  };
52
53
  },
53
54
  watch({ context, prop, track, action }) {
@@ -76,7 +77,7 @@ var machine = createMachine({
76
77
  }
77
78
  },
78
79
  entry: ["syncPrevValue", "syncIndicatorRect", "syncTabIndex", "syncSsr"],
79
- exit: ["cleanupObserver"],
80
+ exit: ["cleanupObserver", "cancelFocusFrame"],
80
81
  states: {
81
82
  idle: {
82
83
  on: {
@@ -91,6 +92,7 @@ var machine = createMachine({
91
92
  }
92
93
  },
93
94
  focused: {
95
+ exit: ["cancelFocusFrame"],
94
96
  on: {
95
97
  TAB_CLICK: {
96
98
  actions: ["setFocusedValue", "setValue", "requestNavigation"]
@@ -179,24 +181,24 @@ var machine = createMachine({
179
181
  clearValue({ context }) {
180
182
  context.set("value", null);
181
183
  },
182
- focusFirstTab({ scope }) {
183
- raf(() => {
184
+ focusFirstTab({ scope, refs }) {
185
+ refs.get("focusFrame").request(() => {
184
186
  dom.getFirstTriggerEl(scope)?.focus();
185
187
  });
186
188
  },
187
- focusLastTab({ scope }) {
188
- raf(() => {
189
+ focusLastTab({ scope, refs }) {
190
+ refs.get("focusFrame").request(() => {
189
191
  dom.getLastTriggerEl(scope)?.focus();
190
192
  });
191
193
  },
192
- focusNextTab({ context, prop, scope, event }) {
194
+ focusNextTab({ context, prop, scope, event, refs }) {
193
195
  const focusedValue = event.value ?? context.get("focusedValue");
194
196
  if (!focusedValue) return;
195
197
  const triggerEl = dom.getNextTriggerEl(scope, {
196
198
  value: focusedValue,
197
199
  loopFocus: prop("loopFocus")
198
200
  });
199
- raf(() => {
201
+ refs.get("focusFrame").request(() => {
200
202
  if (prop("composite")) {
201
203
  triggerEl?.focus();
202
204
  } else if (triggerEl?.dataset.value != null) {
@@ -204,14 +206,14 @@ var machine = createMachine({
204
206
  }
205
207
  });
206
208
  },
207
- focusPrevTab({ context, prop, scope, event }) {
209
+ focusPrevTab({ context, prop, scope, event, refs }) {
208
210
  const focusedValue = event.value ?? context.get("focusedValue");
209
211
  if (!focusedValue) return;
210
212
  const triggerEl = dom.getPrevTriggerEl(scope, {
211
213
  value: focusedValue,
212
214
  loopFocus: prop("loopFocus")
213
215
  });
214
- raf(() => {
216
+ refs.get("focusFrame").request(() => {
215
217
  if (prop("composite")) {
216
218
  triggerEl?.focus();
217
219
  } else if (triggerEl?.dataset.value != null) {
@@ -233,6 +235,9 @@ var machine = createMachine({
233
235
  }
234
236
  });
235
237
  },
238
+ cancelFocusFrame({ refs }) {
239
+ refs.get("focusFrame").cancel();
240
+ },
236
241
  cleanupObserver({ refs }) {
237
242
  const cleanup = refs.get("indicatorCleanup");
238
243
  if (cleanup) cleanup();
@@ -1,5 +1,6 @@
1
1
  import { TabsProps, ContentProps, TriggerProps } from './tabs.types.mjs';
2
2
  import '@zag-js/core';
3
+ import '@zag-js/dom-query';
3
4
  import '@zag-js/types';
4
5
 
5
6
  declare const props: (keyof TabsProps)[];
@@ -1,5 +1,6 @@
1
1
  import { TabsProps, ContentProps, TriggerProps } from './tabs.types.js';
2
2
  import '@zag-js/core';
3
+ import '@zag-js/dom-query';
3
4
  import '@zag-js/types';
4
5
 
5
6
  declare const props: (keyof TabsProps)[];
@@ -1,4 +1,5 @@
1
1
  import { Machine, EventObject, Service } from '@zag-js/core';
2
+ import { AnimationFrame } from '@zag-js/dom-query';
2
3
  import { PropTypes, RequiredBy, DirectionProperty, CommonProperties, Rect } from '@zag-js/types';
3
4
 
4
5
  interface ValueChangeDetails {
@@ -97,6 +98,7 @@ type TabsSchema = {
97
98
  refs: {
98
99
  indicatorCleanup: VoidFunction | null | undefined;
99
100
  prevValue: string | null;
101
+ focusFrame: AnimationFrame;
100
102
  };
101
103
  computed: {
102
104
  focused: boolean;
@@ -1,4 +1,5 @@
1
1
  import { Machine, EventObject, Service } from '@zag-js/core';
2
+ import { AnimationFrame } from '@zag-js/dom-query';
2
3
  import { PropTypes, RequiredBy, DirectionProperty, CommonProperties, Rect } from '@zag-js/types';
3
4
 
4
5
  interface ValueChangeDetails {
@@ -97,6 +98,7 @@ type TabsSchema = {
97
98
  refs: {
98
99
  indicatorCleanup: VoidFunction | null | undefined;
99
100
  prevValue: string | null;
101
+ focusFrame: AnimationFrame;
100
102
  };
101
103
  computed: {
102
104
  focused: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tabs",
3
- "version": "1.45.0",
3
+ "version": "1.47.0",
4
4
  "description": "Core logic for the tabs widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -29,11 +29,11 @@
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/dom-query": "1.45.0",
34
- "@zag-js/utils": "1.45.0",
35
- "@zag-js/core": "1.45.0",
36
- "@zag-js/types": "1.45.0"
32
+ "@zag-js/anatomy": "1.47.0",
33
+ "@zag-js/dom-query": "1.47.0",
34
+ "@zag-js/utils": "1.47.0",
35
+ "@zag-js/core": "1.47.0",
36
+ "@zag-js/types": "1.47.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "clean-package": "2.2.0"