@zag-js/tabs 0.80.0 → 0.81.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/dist/index.d.mts CHANGED
@@ -11,6 +11,10 @@ interface ValueChangeDetails {
11
11
  interface FocusChangeDetails {
12
12
  focusedValue: string;
13
13
  }
14
+ interface NavigateDetails {
15
+ value: string | null;
16
+ node: HTMLAnchorElement;
17
+ }
14
18
  interface IntlTranslations {
15
19
  listLabel?: string | undefined;
16
20
  }
@@ -71,6 +75,11 @@ interface PublicContext extends DirectionProperty, CommonProperties {
71
75
  * Whether the active tab can be deselected when clicking on it.
72
76
  */
73
77
  deselectable?: boolean | undefined;
78
+ /**
79
+ * Function to navigate to the selected tab when clicking on it.
80
+ * Useful if tab triggers are anchor elements.
81
+ */
82
+ navigate: (details: NavigateDetails) => void;
74
83
  }
75
84
  type UserDefinedContext = RequiredBy<PublicContext, "id">;
76
85
  type ComputedContext = Readonly<{}>;
@@ -167,11 +176,11 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
167
176
 
168
177
  declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
169
178
 
170
- declare const props: ("value" | "dir" | "id" | "getRootNode" | "orientation" | "ids" | "translations" | "loopFocus" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable")[];
171
- declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "value" | "dir" | "id" | "getRootNode" | "orientation" | "ids" | "translations" | "loopFocus" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable">];
179
+ declare const props: ("dir" | "id" | "value" | "orientation" | "getRootNode" | "ids" | "translations" | "loopFocus" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable" | "navigate")[];
180
+ declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "dir" | "id" | "value" | "orientation" | "getRootNode" | "ids" | "translations" | "loopFocus" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable" | "navigate">];
172
181
  declare const triggerProps: (keyof TriggerProps)[];
173
182
  declare const splitTriggerProps: <Props extends TriggerProps>(props: Props) => [TriggerProps, Omit<Props, keyof TriggerProps>];
174
183
  declare const contentProps: "value"[];
175
184
  declare const splitContentProps: <Props extends ContentProps>(props: Props) => [ContentProps, Omit<Props, "value">];
176
185
 
177
- export { type MachineApi as Api, type ContentProps, type UserDefinedContext as Context, type ElementIds, type FocusChangeDetails, type IntlTranslations, type Service, type TriggerProps, type ValueChangeDetails, anatomy, connect, contentProps, machine, props, splitContentProps, splitProps, splitTriggerProps, triggerProps };
186
+ export { type MachineApi as Api, type ContentProps, type UserDefinedContext as Context, type ElementIds, type FocusChangeDetails, type IntlTranslations, type NavigateDetails, type Service, type TriggerProps, type ValueChangeDetails, anatomy, connect, contentProps, machine, props, splitContentProps, splitProps, splitTriggerProps, triggerProps };
package/dist/index.d.ts CHANGED
@@ -11,6 +11,10 @@ interface ValueChangeDetails {
11
11
  interface FocusChangeDetails {
12
12
  focusedValue: string;
13
13
  }
14
+ interface NavigateDetails {
15
+ value: string | null;
16
+ node: HTMLAnchorElement;
17
+ }
14
18
  interface IntlTranslations {
15
19
  listLabel?: string | undefined;
16
20
  }
@@ -71,6 +75,11 @@ interface PublicContext extends DirectionProperty, CommonProperties {
71
75
  * Whether the active tab can be deselected when clicking on it.
72
76
  */
73
77
  deselectable?: boolean | undefined;
78
+ /**
79
+ * Function to navigate to the selected tab when clicking on it.
80
+ * Useful if tab triggers are anchor elements.
81
+ */
82
+ navigate: (details: NavigateDetails) => void;
74
83
  }
75
84
  type UserDefinedContext = RequiredBy<PublicContext, "id">;
76
85
  type ComputedContext = Readonly<{}>;
@@ -167,11 +176,11 @@ declare function connect<T extends PropTypes>(state: State, send: Send, normaliz
167
176
 
168
177
  declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
169
178
 
170
- declare const props: ("value" | "dir" | "id" | "getRootNode" | "orientation" | "ids" | "translations" | "loopFocus" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable")[];
171
- declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "value" | "dir" | "id" | "getRootNode" | "orientation" | "ids" | "translations" | "loopFocus" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable">];
179
+ declare const props: ("dir" | "id" | "value" | "orientation" | "getRootNode" | "ids" | "translations" | "loopFocus" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable" | "navigate")[];
180
+ declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "dir" | "id" | "value" | "orientation" | "getRootNode" | "ids" | "translations" | "loopFocus" | "activationMode" | "onValueChange" | "onFocusChange" | "composite" | "deselectable" | "navigate">];
172
181
  declare const triggerProps: (keyof TriggerProps)[];
173
182
  declare const splitTriggerProps: <Props extends TriggerProps>(props: Props) => [TriggerProps, Omit<Props, keyof TriggerProps>];
174
183
  declare const contentProps: "value"[];
175
184
  declare const splitContentProps: <Props extends ContentProps>(props: Props) => [ContentProps, Omit<Props, "value">];
176
185
 
177
- export { type MachineApi as Api, type ContentProps, type UserDefinedContext as Context, type ElementIds, type FocusChangeDetails, type IntlTranslations, type Service, type TriggerProps, type ValueChangeDetails, anatomy, connect, contentProps, machine, props, splitContentProps, splitProps, splitTriggerProps, triggerProps };
186
+ export { type MachineApi as Api, type ContentProps, type UserDefinedContext as Context, type ElementIds, type FocusChangeDetails, type IntlTranslations, type NavigateDetails, type Service, type TriggerProps, type ValueChangeDetails, anatomy, connect, contentProps, machine, props, splitContentProps, splitProps, splitTriggerProps, triggerProps };
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var anatomy$1 = require('@zag-js/anatomy');
4
- var domEvent = require('@zag-js/dom-event');
5
4
  var domQuery = require('@zag-js/dom-query');
6
5
  var utils = require('@zag-js/utils');
7
6
  var core = require('@zag-js/core');
@@ -150,7 +149,7 @@ function connect(state, send, normalize) {
150
149
  send({ type: "ENTER" });
151
150
  }
152
151
  };
153
- let key = domEvent.getEventKey(event, state.context);
152
+ let key = domQuery.getEventKey(event, state.context);
154
153
  const exec = keyMap[key];
155
154
  if (exec) {
156
155
  event.preventDefault();
@@ -252,6 +251,9 @@ function machine(userContext) {
252
251
  value: null,
253
252
  loopFocus: true,
254
253
  composite: true,
254
+ navigate(details) {
255
+ domQuery.clickIfLink(details.node);
256
+ },
255
257
  ...ctx,
256
258
  focusedValue: ctx.value ?? null,
257
259
  ssr: true,
@@ -262,7 +264,7 @@ function machine(userContext) {
262
264
  }
263
265
  },
264
266
  watch: {
265
- value: ["allowIndicatorTransition", "syncIndicatorRect", "syncTabIndex", "clickIfLink"],
267
+ value: ["allowIndicatorTransition", "syncIndicatorRect", "syncTabIndex", "navigateIfNeeded"],
266
268
  dir: ["syncIndicatorRect"],
267
269
  orientation: ["syncIndicatorRect"]
268
270
  },
@@ -469,8 +471,10 @@ function machine(userContext) {
469
471
  }
470
472
  });
471
473
  },
472
- clickIfLink(ctx2) {
473
- domEvent.clickIfLink(dom.getSelectedTriggerEl(ctx2));
474
+ navigateIfNeeded(ctx2) {
475
+ const triggerEl = dom.getSelectedTriggerEl(ctx2);
476
+ if (!domQuery.isAnchorElement(triggerEl)) return;
477
+ ctx2.navigate({ value: ctx2.value, node: triggerEl });
474
478
  }
475
479
  }
476
480
  }
@@ -501,16 +505,17 @@ var set = {
501
505
  var props = types.createProps()([
502
506
  "activationMode",
503
507
  "composite",
508
+ "deselectable",
504
509
  "dir",
505
510
  "getRootNode",
506
511
  "id",
507
512
  "ids",
508
513
  "loopFocus",
514
+ "navigate",
509
515
  "onFocusChange",
510
516
  "onValueChange",
511
517
  "orientation",
512
518
  "translations",
513
- "deselectable",
514
519
  "value"
515
520
  ]);
516
521
  var splitProps = utils.createSplitProps(props);
package/dist/index.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import { createAnatomy } from '@zag-js/anatomy';
2
- import { getEventKey, clickIfLink } from '@zag-js/dom-event';
3
- import { createScope, queryAll, nextById, prevById, itemById, dataAttr, isSelfTarget, isComposingEvent, isSafari, raf, getFocusables, nextTick } from '@zag-js/dom-query';
2
+ import { createScope, queryAll, nextById, prevById, itemById, dataAttr, isSelfTarget, isComposingEvent, getEventKey, isSafari, clickIfLink, raf, getFocusables, nextTick, isAnchorElement } from '@zag-js/dom-query';
4
3
  import { first, last, createSplitProps, compact, isEqual } from '@zag-js/utils';
5
4
  import { createMachine, guards } from '@zag-js/core';
6
5
  import { trackElementRect } from '@zag-js/element-rect';
@@ -250,6 +249,9 @@ function machine(userContext) {
250
249
  value: null,
251
250
  loopFocus: true,
252
251
  composite: true,
252
+ navigate(details) {
253
+ clickIfLink(details.node);
254
+ },
253
255
  ...ctx,
254
256
  focusedValue: ctx.value ?? null,
255
257
  ssr: true,
@@ -260,7 +262,7 @@ function machine(userContext) {
260
262
  }
261
263
  },
262
264
  watch: {
263
- value: ["allowIndicatorTransition", "syncIndicatorRect", "syncTabIndex", "clickIfLink"],
265
+ value: ["allowIndicatorTransition", "syncIndicatorRect", "syncTabIndex", "navigateIfNeeded"],
264
266
  dir: ["syncIndicatorRect"],
265
267
  orientation: ["syncIndicatorRect"]
266
268
  },
@@ -467,8 +469,10 @@ function machine(userContext) {
467
469
  }
468
470
  });
469
471
  },
470
- clickIfLink(ctx2) {
471
- clickIfLink(dom.getSelectedTriggerEl(ctx2));
472
+ navigateIfNeeded(ctx2) {
473
+ const triggerEl = dom.getSelectedTriggerEl(ctx2);
474
+ if (!isAnchorElement(triggerEl)) return;
475
+ ctx2.navigate({ value: ctx2.value, node: triggerEl });
472
476
  }
473
477
  }
474
478
  }
@@ -499,16 +503,17 @@ var set = {
499
503
  var props = createProps()([
500
504
  "activationMode",
501
505
  "composite",
506
+ "deselectable",
502
507
  "dir",
503
508
  "getRootNode",
504
509
  "id",
505
510
  "ids",
506
511
  "loopFocus",
512
+ "navigate",
507
513
  "onFocusChange",
508
514
  "onValueChange",
509
515
  "orientation",
510
516
  "translations",
511
- "deselectable",
512
517
  "value"
513
518
  ]);
514
519
  var splitProps = createSplitProps(props);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/tabs",
3
- "version": "0.80.0",
3
+ "version": "0.81.1",
4
4
  "description": "Core logic for the tabs widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -26,13 +26,12 @@
26
26
  "url": "https://github.com/chakra-ui/zag/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@zag-js/anatomy": "0.80.0",
30
- "@zag-js/dom-query": "0.80.0",
31
- "@zag-js/dom-event": "0.80.0",
32
- "@zag-js/element-rect": "0.80.0",
33
- "@zag-js/utils": "0.80.0",
34
- "@zag-js/core": "0.80.0",
35
- "@zag-js/types": "0.80.0"
29
+ "@zag-js/anatomy": "0.81.1",
30
+ "@zag-js/dom-query": "0.81.1",
31
+ "@zag-js/element-rect": "0.81.1",
32
+ "@zag-js/utils": "0.81.1",
33
+ "@zag-js/core": "0.81.1",
34
+ "@zag-js/types": "0.81.1"
36
35
  },
37
36
  "devDependencies": {
38
37
  "clean-package": "2.2.0"