@zag-js/tabs 0.2.11 → 0.2.12
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/{chunk-IVTIBLCN.mjs → chunk-5JW3YJ3I.mjs} +18 -42
- package/dist/chunk-5ZMNIWHF.mjs +53 -0
- package/dist/{chunk-3DBUWLYX.mjs → chunk-JG2VX4ST.mjs} +6 -66
- package/dist/index.js +46 -188
- package/dist/index.mjs +3 -3
- package/dist/tabs.connect.d.ts +15 -0
- package/dist/tabs.connect.js +32 -110
- package/dist/tabs.connect.mjs +2 -2
- package/dist/tabs.dom.d.ts +9 -6
- package/dist/tabs.dom.js +9 -65
- package/dist/tabs.dom.mjs +1 -1
- package/dist/tabs.machine.js +22 -142
- package/dist/tabs.machine.mjs +2 -2
- package/dist/tabs.types.d.ts +0 -4
- package/package.json +7 -5
- package/dist/chunk-4CROPD6E.mjs +0 -121
|
@@ -3,60 +3,36 @@ import {
|
|
|
3
3
|
} from "./chunk-S2KW2DT4.mjs";
|
|
4
4
|
import {
|
|
5
5
|
dom
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
|
|
8
|
-
// ../../utilities/dom/src/attrs.ts
|
|
9
|
-
var dataAttr = (guard) => {
|
|
10
|
-
return guard ? "" : void 0;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
// ../../utilities/dom/src/platform.ts
|
|
14
|
-
var isDom = () => typeof window !== "undefined";
|
|
15
|
-
function getPlatform() {
|
|
16
|
-
const agent = navigator.userAgentData;
|
|
17
|
-
return agent?.platform ?? navigator.platform;
|
|
18
|
-
}
|
|
19
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
20
|
-
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
21
|
-
var isSafari = () => isApple() && vn(/apple/i);
|
|
22
|
-
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
23
|
-
|
|
24
|
-
// ../../utilities/dom/src/keyboard-event.ts
|
|
25
|
-
var rtlKeyMap = {
|
|
26
|
-
ArrowLeft: "ArrowRight",
|
|
27
|
-
ArrowRight: "ArrowLeft"
|
|
28
|
-
};
|
|
29
|
-
var sameKeyMap = {
|
|
30
|
-
Up: "ArrowUp",
|
|
31
|
-
Down: "ArrowDown",
|
|
32
|
-
Esc: "Escape",
|
|
33
|
-
" ": "Space",
|
|
34
|
-
",": "Comma",
|
|
35
|
-
Left: "ArrowLeft",
|
|
36
|
-
Right: "ArrowRight"
|
|
37
|
-
};
|
|
38
|
-
function getEventKey(event, options = {}) {
|
|
39
|
-
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
40
|
-
let { key } = event;
|
|
41
|
-
key = sameKeyMap[key] ?? key;
|
|
42
|
-
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
43
|
-
if (isRtl && key in rtlKeyMap) {
|
|
44
|
-
key = rtlKeyMap[key];
|
|
45
|
-
}
|
|
46
|
-
return key;
|
|
47
|
-
}
|
|
6
|
+
} from "./chunk-5ZMNIWHF.mjs";
|
|
48
7
|
|
|
49
8
|
// src/tabs.connect.ts
|
|
9
|
+
import { getEventKey } from "@zag-js/dom-event";
|
|
10
|
+
import { dataAttr, isSafari } from "@zag-js/dom-query";
|
|
50
11
|
function connect(state, send, normalize) {
|
|
51
12
|
const translations = state.context.translations;
|
|
52
13
|
const isFocused = state.matches("focused");
|
|
53
14
|
return {
|
|
15
|
+
/**
|
|
16
|
+
* The current value of the tabs.
|
|
17
|
+
*/
|
|
54
18
|
value: state.context.value,
|
|
19
|
+
/**
|
|
20
|
+
* The value of the tab that is currently focused.
|
|
21
|
+
*/
|
|
55
22
|
focusedValue: state.context.focusedValue,
|
|
23
|
+
/**
|
|
24
|
+
* The previous values of the tabs in sequence of selection.
|
|
25
|
+
*/
|
|
56
26
|
previousValues: Array.from(state.context.previousValues),
|
|
27
|
+
/**
|
|
28
|
+
* Sets the value of the tabs.
|
|
29
|
+
*/
|
|
57
30
|
setValue(value) {
|
|
58
31
|
send({ type: "SET_VALUE", value });
|
|
59
32
|
},
|
|
33
|
+
/**
|
|
34
|
+
* Clears the value of the tabs.
|
|
35
|
+
*/
|
|
60
36
|
clearValue() {
|
|
61
37
|
send({ type: "CLEAR_VALUE" });
|
|
62
38
|
},
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// src/tabs.dom.ts
|
|
2
|
+
import { createScope, itemById, nextById, prevById, queryAll } from "@zag-js/dom-query";
|
|
3
|
+
import { first, last } from "@zag-js/utils";
|
|
4
|
+
var dom = createScope({
|
|
5
|
+
getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
|
|
6
|
+
getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
|
|
7
|
+
getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
|
|
8
|
+
getContentGroupId: (ctx) => ctx.ids?.contentGroup ?? `tabs:${ctx.id}:content-group`,
|
|
9
|
+
getTriggerId: (ctx, id) => ctx.ids?.trigger ?? `tabs:${ctx.id}:trigger-${id}`,
|
|
10
|
+
getIndicatorId: (ctx) => `tabs:${ctx.id}:indicator`,
|
|
11
|
+
getTablistEl: (ctx) => dom.getById(ctx, dom.getTablistId(ctx)),
|
|
12
|
+
getContentEl: (ctx, id) => dom.getById(ctx, dom.getContentId(ctx, id)),
|
|
13
|
+
getTriggerEl: (ctx, id) => dom.getById(ctx, dom.getTriggerId(ctx, id)),
|
|
14
|
+
getIndicatorEl: (ctx) => dom.getById(ctx, dom.getIndicatorId(ctx)),
|
|
15
|
+
getElements: (ctx) => {
|
|
16
|
+
const ownerId = CSS.escape(dom.getTablistId(ctx));
|
|
17
|
+
const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
|
|
18
|
+
return queryAll(dom.getTablistEl(ctx), selector);
|
|
19
|
+
},
|
|
20
|
+
getFirstEl: (ctx) => first(dom.getElements(ctx)),
|
|
21
|
+
getLastEl: (ctx) => last(dom.getElements(ctx)),
|
|
22
|
+
getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
23
|
+
getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
24
|
+
getActiveContentEl: (ctx) => {
|
|
25
|
+
if (!ctx.value)
|
|
26
|
+
return;
|
|
27
|
+
const id = dom.getContentId(ctx, ctx.value);
|
|
28
|
+
return dom.getById(ctx, id);
|
|
29
|
+
},
|
|
30
|
+
getRectById: (ctx, id) => {
|
|
31
|
+
const empty = {
|
|
32
|
+
offsetLeft: 0,
|
|
33
|
+
offsetTop: 0,
|
|
34
|
+
offsetWidth: 0,
|
|
35
|
+
offsetHeight: 0
|
|
36
|
+
};
|
|
37
|
+
const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
|
|
38
|
+
if (ctx.isVertical) {
|
|
39
|
+
return {
|
|
40
|
+
top: `${tab.offsetTop}px`,
|
|
41
|
+
height: `${tab.offsetHeight}px`
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
left: `${tab.offsetLeft}px`,
|
|
46
|
+
width: `${tab.offsetWidth}px`
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export {
|
|
52
|
+
dom
|
|
53
|
+
};
|
|
@@ -1,73 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
dom
|
|
3
|
-
|
|
4
|
-
isHTMLElement,
|
|
5
|
-
isVisible
|
|
6
|
-
} from "./chunk-4CROPD6E.mjs";
|
|
2
|
+
dom
|
|
3
|
+
} from "./chunk-5ZMNIWHF.mjs";
|
|
7
4
|
|
|
8
5
|
// src/tabs.machine.ts
|
|
9
6
|
import { createMachine, guards } from "@zag-js/core";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
14
|
-
|
|
15
|
-
// ../../utilities/core/src/object.ts
|
|
16
|
-
function compact(obj) {
|
|
17
|
-
if (obj === void 0)
|
|
18
|
-
return obj;
|
|
19
|
-
return Object.fromEntries(
|
|
20
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// ../../utilities/dom/src/focusable.ts
|
|
25
|
-
var focusableSelector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
|
|
26
|
-
var getFocusables = (container, includeContainer = false) => {
|
|
27
|
-
if (!container)
|
|
28
|
-
return [];
|
|
29
|
-
const elements = Array.from(container.querySelectorAll(focusableSelector));
|
|
30
|
-
const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
|
|
31
|
-
if (include && isHTMLElement(container) && isFocusable(container)) {
|
|
32
|
-
elements.unshift(container);
|
|
33
|
-
}
|
|
34
|
-
const focusableElements = elements.filter(isFocusable);
|
|
35
|
-
focusableElements.forEach((element, i) => {
|
|
36
|
-
if (isFrame(element) && element.contentDocument) {
|
|
37
|
-
const frameBody = element.contentDocument.body;
|
|
38
|
-
focusableElements.splice(i, 1, ...getFocusables(frameBody));
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
return focusableElements;
|
|
42
|
-
};
|
|
43
|
-
function isFocusable(element) {
|
|
44
|
-
if (!element)
|
|
45
|
-
return false;
|
|
46
|
-
return element.matches(focusableSelector) && isVisible(element);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// ../../utilities/dom/src/next-tick.ts
|
|
50
|
-
function nextTick(fn) {
|
|
51
|
-
const set = /* @__PURE__ */ new Set();
|
|
52
|
-
function raf2(fn2) {
|
|
53
|
-
const id = globalThis.requestAnimationFrame(fn2);
|
|
54
|
-
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
55
|
-
}
|
|
56
|
-
raf2(() => raf2(fn));
|
|
57
|
-
return function cleanup() {
|
|
58
|
-
set.forEach(function(fn2) {
|
|
59
|
-
fn2();
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function raf(fn) {
|
|
64
|
-
const id = globalThis.requestAnimationFrame(fn);
|
|
65
|
-
return function cleanup() {
|
|
66
|
-
globalThis.cancelAnimationFrame(id);
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// src/tabs.machine.ts
|
|
7
|
+
import { nextTick, raf } from "@zag-js/dom-query";
|
|
8
|
+
import { getFocusables } from "@zag-js/tabbable";
|
|
9
|
+
import { compact } from "@zag-js/utils";
|
|
71
10
|
var { not } = guards;
|
|
72
11
|
function machine(userContext) {
|
|
73
12
|
const ctx = compact(userContext);
|
|
@@ -237,6 +176,7 @@ function machine(userContext) {
|
|
|
237
176
|
ctx2.previousValues = pushUnique(Array.from(ctx2.previousValues), ctx2.value);
|
|
238
177
|
}
|
|
239
178
|
},
|
|
179
|
+
// if tab panel contains focusable elements, remove the tabindex attribute
|
|
240
180
|
setContentTabIndex(ctx2) {
|
|
241
181
|
raf(() => {
|
|
242
182
|
const panel = dom.getActiveContentEl(ctx2);
|
package/dist/index.js
CHANGED
|
@@ -31,175 +31,14 @@ var import_anatomy = require("@zag-js/anatomy");
|
|
|
31
31
|
var anatomy = (0, import_anatomy.createAnatomy)("tabs").parts("root", "tablist", "trigger", "contentGroup", "content", "indicator");
|
|
32
32
|
var parts = anatomy.build();
|
|
33
33
|
|
|
34
|
-
//
|
|
35
|
-
var
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// ../../utilities/core/src/array.ts
|
|
40
|
-
var first = (v) => v[0];
|
|
41
|
-
var last = (v) => v[v.length - 1];
|
|
42
|
-
|
|
43
|
-
// ../../utilities/core/src/guard.ts
|
|
44
|
-
var isArray = (v) => Array.isArray(v);
|
|
45
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
46
|
-
|
|
47
|
-
// ../../utilities/core/src/object.ts
|
|
48
|
-
function compact(obj) {
|
|
49
|
-
if (obj === void 0)
|
|
50
|
-
return obj;
|
|
51
|
-
return Object.fromEntries(
|
|
52
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// ../../utilities/dom/src/platform.ts
|
|
57
|
-
var isDom = () => typeof window !== "undefined";
|
|
58
|
-
function getPlatform() {
|
|
59
|
-
const agent = navigator.userAgentData;
|
|
60
|
-
return agent?.platform ?? navigator.platform;
|
|
61
|
-
}
|
|
62
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
63
|
-
var vn = (v) => isDom() && v.test(navigator.vendor);
|
|
64
|
-
var isSafari = () => isApple() && vn(/apple/i);
|
|
65
|
-
var isApple = () => pt(/mac|iphone|ipad|ipod/i);
|
|
66
|
-
|
|
67
|
-
// ../../utilities/dom/src/query.ts
|
|
68
|
-
function isDocument(el) {
|
|
69
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
70
|
-
}
|
|
71
|
-
function isWindow(value) {
|
|
72
|
-
return value?.toString() === "[object Window]";
|
|
73
|
-
}
|
|
74
|
-
function isFrame(element) {
|
|
75
|
-
return element.localName === "iframe";
|
|
76
|
-
}
|
|
77
|
-
function getDocument(el) {
|
|
78
|
-
if (isWindow(el))
|
|
79
|
-
return el.document;
|
|
80
|
-
if (isDocument(el))
|
|
81
|
-
return el;
|
|
82
|
-
return el?.ownerDocument ?? document;
|
|
83
|
-
}
|
|
84
|
-
function defineDomHelpers(helpers) {
|
|
85
|
-
const dom2 = {
|
|
86
|
-
getRootNode: (ctx) => ctx.getRootNode?.() ?? document,
|
|
87
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
88
|
-
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
89
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
90
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
91
|
-
};
|
|
92
|
-
return {
|
|
93
|
-
...dom2,
|
|
94
|
-
...helpers
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
function isHTMLElement(v) {
|
|
98
|
-
return typeof v === "object" && v?.nodeType === Node.ELEMENT_NODE && typeof v?.nodeName === "string";
|
|
99
|
-
}
|
|
100
|
-
function isVisible(el) {
|
|
101
|
-
if (!isHTMLElement(el))
|
|
102
|
-
return false;
|
|
103
|
-
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// ../../utilities/dom/src/focusable.ts
|
|
107
|
-
var focusableSelector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
|
|
108
|
-
var getFocusables = (container, includeContainer = false) => {
|
|
109
|
-
if (!container)
|
|
110
|
-
return [];
|
|
111
|
-
const elements = Array.from(container.querySelectorAll(focusableSelector));
|
|
112
|
-
const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
|
|
113
|
-
if (include && isHTMLElement(container) && isFocusable(container)) {
|
|
114
|
-
elements.unshift(container);
|
|
115
|
-
}
|
|
116
|
-
const focusableElements = elements.filter(isFocusable);
|
|
117
|
-
focusableElements.forEach((element, i) => {
|
|
118
|
-
if (isFrame(element) && element.contentDocument) {
|
|
119
|
-
const frameBody = element.contentDocument.body;
|
|
120
|
-
focusableElements.splice(i, 1, ...getFocusables(frameBody));
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
return focusableElements;
|
|
124
|
-
};
|
|
125
|
-
function isFocusable(element) {
|
|
126
|
-
if (!element)
|
|
127
|
-
return false;
|
|
128
|
-
return element.matches(focusableSelector) && isVisible(element);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// ../../utilities/dom/src/keyboard-event.ts
|
|
132
|
-
var rtlKeyMap = {
|
|
133
|
-
ArrowLeft: "ArrowRight",
|
|
134
|
-
ArrowRight: "ArrowLeft"
|
|
135
|
-
};
|
|
136
|
-
var sameKeyMap = {
|
|
137
|
-
Up: "ArrowUp",
|
|
138
|
-
Down: "ArrowDown",
|
|
139
|
-
Esc: "Escape",
|
|
140
|
-
" ": "Space",
|
|
141
|
-
",": "Comma",
|
|
142
|
-
Left: "ArrowLeft",
|
|
143
|
-
Right: "ArrowRight"
|
|
144
|
-
};
|
|
145
|
-
function getEventKey(event, options = {}) {
|
|
146
|
-
const { dir = "ltr", orientation = "horizontal" } = options;
|
|
147
|
-
let { key } = event;
|
|
148
|
-
key = sameKeyMap[key] ?? key;
|
|
149
|
-
const isRtl = dir === "rtl" && orientation === "horizontal";
|
|
150
|
-
if (isRtl && key in rtlKeyMap) {
|
|
151
|
-
key = rtlKeyMap[key];
|
|
152
|
-
}
|
|
153
|
-
return key;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// ../../utilities/dom/src/next-tick.ts
|
|
157
|
-
function nextTick(fn) {
|
|
158
|
-
const set = /* @__PURE__ */ new Set();
|
|
159
|
-
function raf2(fn2) {
|
|
160
|
-
const id = globalThis.requestAnimationFrame(fn2);
|
|
161
|
-
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
162
|
-
}
|
|
163
|
-
raf2(() => raf2(fn));
|
|
164
|
-
return function cleanup() {
|
|
165
|
-
set.forEach(function(fn2) {
|
|
166
|
-
fn2();
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
function raf(fn) {
|
|
171
|
-
const id = globalThis.requestAnimationFrame(fn);
|
|
172
|
-
return function cleanup() {
|
|
173
|
-
globalThis.cancelAnimationFrame(id);
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// ../../utilities/dom/src/nodelist.ts
|
|
178
|
-
function queryAll(root, selector) {
|
|
179
|
-
return Array.from(root?.querySelectorAll(selector) ?? []);
|
|
180
|
-
}
|
|
181
|
-
function itemById(v, id) {
|
|
182
|
-
return v.find((node) => node.id === id);
|
|
183
|
-
}
|
|
184
|
-
function indexOfId(v, id) {
|
|
185
|
-
const item = itemById(v, id);
|
|
186
|
-
return item ? v.indexOf(item) : -1;
|
|
187
|
-
}
|
|
188
|
-
function nextById(v, id, loop = true) {
|
|
189
|
-
let idx = indexOfId(v, id);
|
|
190
|
-
idx = loop ? (idx + 1) % v.length : Math.min(idx + 1, v.length - 1);
|
|
191
|
-
return v[idx];
|
|
192
|
-
}
|
|
193
|
-
function prevById(v, id, loop = true) {
|
|
194
|
-
let idx = indexOfId(v, id);
|
|
195
|
-
if (idx === -1)
|
|
196
|
-
return loop ? v[v.length - 1] : null;
|
|
197
|
-
idx = loop ? (idx - 1 + v.length) % v.length : Math.max(0, idx - 1);
|
|
198
|
-
return v[idx];
|
|
199
|
-
}
|
|
34
|
+
// src/tabs.connect.ts
|
|
35
|
+
var import_dom_event = require("@zag-js/dom-event");
|
|
36
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
200
37
|
|
|
201
38
|
// src/tabs.dom.ts
|
|
202
|
-
var
|
|
39
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
40
|
+
var import_utils = require("@zag-js/utils");
|
|
41
|
+
var dom = (0, import_dom_query.createScope)({
|
|
203
42
|
getRootId: (ctx) => ctx.ids?.root ?? `tabs:${ctx.id}`,
|
|
204
43
|
getTablistId: (ctx) => ctx.ids?.tablist ?? `tabs:${ctx.id}:list`,
|
|
205
44
|
getContentId: (ctx, id) => ctx.ids?.content ?? `tabs:${ctx.id}:content-${id}`,
|
|
@@ -213,12 +52,12 @@ var dom = defineDomHelpers({
|
|
|
213
52
|
getElements: (ctx) => {
|
|
214
53
|
const ownerId = CSS.escape(dom.getTablistId(ctx));
|
|
215
54
|
const selector = `[role=tab][data-ownedby='${ownerId}']:not([disabled])`;
|
|
216
|
-
return queryAll(dom.getTablistEl(ctx), selector);
|
|
55
|
+
return (0, import_dom_query.queryAll)(dom.getTablistEl(ctx), selector);
|
|
217
56
|
},
|
|
218
|
-
getFirstEl: (ctx) => first(dom.getElements(ctx)),
|
|
219
|
-
getLastEl: (ctx) => last(dom.getElements(ctx)),
|
|
220
|
-
getNextEl: (ctx, id) => nextById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
221
|
-
getPrevEl: (ctx, id) => prevById(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
57
|
+
getFirstEl: (ctx) => (0, import_utils.first)(dom.getElements(ctx)),
|
|
58
|
+
getLastEl: (ctx) => (0, import_utils.last)(dom.getElements(ctx)),
|
|
59
|
+
getNextEl: (ctx, id) => (0, import_dom_query.nextById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
60
|
+
getPrevEl: (ctx, id) => (0, import_dom_query.prevById)(dom.getElements(ctx), dom.getTriggerId(ctx, id), ctx.loop),
|
|
222
61
|
getActiveContentEl: (ctx) => {
|
|
223
62
|
if (!ctx.value)
|
|
224
63
|
return;
|
|
@@ -232,7 +71,7 @@ var dom = defineDomHelpers({
|
|
|
232
71
|
offsetWidth: 0,
|
|
233
72
|
offsetHeight: 0
|
|
234
73
|
};
|
|
235
|
-
const tab = itemById(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
|
|
74
|
+
const tab = (0, import_dom_query.itemById)(dom.getElements(ctx), dom.getTriggerId(ctx, id)) ?? empty;
|
|
236
75
|
if (ctx.isVertical) {
|
|
237
76
|
return {
|
|
238
77
|
top: `${tab.offsetTop}px`,
|
|
@@ -251,12 +90,27 @@ function connect(state, send, normalize) {
|
|
|
251
90
|
const translations = state.context.translations;
|
|
252
91
|
const isFocused = state.matches("focused");
|
|
253
92
|
return {
|
|
93
|
+
/**
|
|
94
|
+
* The current value of the tabs.
|
|
95
|
+
*/
|
|
254
96
|
value: state.context.value,
|
|
97
|
+
/**
|
|
98
|
+
* The value of the tab that is currently focused.
|
|
99
|
+
*/
|
|
255
100
|
focusedValue: state.context.focusedValue,
|
|
101
|
+
/**
|
|
102
|
+
* The previous values of the tabs in sequence of selection.
|
|
103
|
+
*/
|
|
256
104
|
previousValues: Array.from(state.context.previousValues),
|
|
105
|
+
/**
|
|
106
|
+
* Sets the value of the tabs.
|
|
107
|
+
*/
|
|
257
108
|
setValue(value) {
|
|
258
109
|
send({ type: "SET_VALUE", value });
|
|
259
110
|
},
|
|
111
|
+
/**
|
|
112
|
+
* Clears the value of the tabs.
|
|
113
|
+
*/
|
|
260
114
|
clearValue() {
|
|
261
115
|
send({ type: "CLEAR_VALUE" });
|
|
262
116
|
},
|
|
@@ -264,14 +118,14 @@ function connect(state, send, normalize) {
|
|
|
264
118
|
...parts.root.attrs,
|
|
265
119
|
id: dom.getRootId(state.context),
|
|
266
120
|
"data-orientation": state.context.orientation,
|
|
267
|
-
"data-focus": dataAttr(isFocused),
|
|
121
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
268
122
|
dir: state.context.dir
|
|
269
123
|
}),
|
|
270
124
|
tablistProps: normalize.element({
|
|
271
125
|
...parts.tablist.attrs,
|
|
272
126
|
id: dom.getTablistId(state.context),
|
|
273
127
|
role: "tablist",
|
|
274
|
-
"data-focus": dataAttr(isFocused),
|
|
128
|
+
"data-focus": (0, import_dom_query2.dataAttr)(isFocused),
|
|
275
129
|
"aria-orientation": state.context.orientation,
|
|
276
130
|
"data-orientation": state.context.orientation,
|
|
277
131
|
"aria-label": translations.tablistLabel,
|
|
@@ -299,7 +153,7 @@ function connect(state, send, normalize) {
|
|
|
299
153
|
send({ type: "ENTER", value: state.context.focusedValue });
|
|
300
154
|
}
|
|
301
155
|
};
|
|
302
|
-
let key = getEventKey(event, state.context);
|
|
156
|
+
let key = (0, import_dom_event.getEventKey)(event, state.context);
|
|
303
157
|
const exec = keyMap[key];
|
|
304
158
|
if (exec) {
|
|
305
159
|
event.preventDefault();
|
|
@@ -316,11 +170,11 @@ function connect(state, send, normalize) {
|
|
|
316
170
|
type: "button",
|
|
317
171
|
disabled,
|
|
318
172
|
"data-orientation": state.context.orientation,
|
|
319
|
-
"data-disabled": dataAttr(disabled),
|
|
173
|
+
"data-disabled": (0, import_dom_query2.dataAttr)(disabled),
|
|
320
174
|
"aria-disabled": disabled,
|
|
321
175
|
"data-value": value,
|
|
322
176
|
"aria-selected": selected,
|
|
323
|
-
"data-selected": dataAttr(selected),
|
|
177
|
+
"data-selected": (0, import_dom_query2.dataAttr)(selected),
|
|
324
178
|
"aria-controls": dom.getContentId(state.context, value),
|
|
325
179
|
"data-ownedby": dom.getTablistId(state.context),
|
|
326
180
|
id: dom.getTriggerId(state.context, value),
|
|
@@ -337,7 +191,7 @@ function connect(state, send, normalize) {
|
|
|
337
191
|
onClick(event) {
|
|
338
192
|
if (disabled)
|
|
339
193
|
return;
|
|
340
|
-
if (isSafari()) {
|
|
194
|
+
if ((0, import_dom_query2.isSafari)()) {
|
|
341
195
|
event.currentTarget.focus();
|
|
342
196
|
}
|
|
343
197
|
send({ type: "TAB_CLICK", value });
|
|
@@ -381,9 +235,12 @@ function connect(state, send, normalize) {
|
|
|
381
235
|
|
|
382
236
|
// src/tabs.machine.ts
|
|
383
237
|
var import_core = require("@zag-js/core");
|
|
238
|
+
var import_dom_query3 = require("@zag-js/dom-query");
|
|
239
|
+
var import_tabbable = require("@zag-js/tabbable");
|
|
240
|
+
var import_utils2 = require("@zag-js/utils");
|
|
384
241
|
var { not } = import_core.guards;
|
|
385
242
|
function machine(userContext) {
|
|
386
|
-
const ctx = compact(userContext);
|
|
243
|
+
const ctx = (0, import_utils2.compact)(userContext);
|
|
387
244
|
return (0, import_core.createMachine)(
|
|
388
245
|
{
|
|
389
246
|
initial: "idle",
|
|
@@ -504,31 +361,31 @@ function machine(userContext) {
|
|
|
504
361
|
ctx2.onDelete?.({ value: evt.value });
|
|
505
362
|
},
|
|
506
363
|
focusFirstTab(ctx2) {
|
|
507
|
-
raf(() => dom.getFirstEl(ctx2)?.focus());
|
|
364
|
+
(0, import_dom_query3.raf)(() => dom.getFirstEl(ctx2)?.focus());
|
|
508
365
|
},
|
|
509
366
|
focusLastTab(ctx2) {
|
|
510
|
-
raf(() => dom.getLastEl(ctx2)?.focus());
|
|
367
|
+
(0, import_dom_query3.raf)(() => dom.getLastEl(ctx2)?.focus());
|
|
511
368
|
},
|
|
512
369
|
focusNextTab(ctx2) {
|
|
513
370
|
if (!ctx2.focusedValue)
|
|
514
371
|
return;
|
|
515
372
|
const next = dom.getNextEl(ctx2, ctx2.focusedValue);
|
|
516
|
-
raf(() => next?.focus());
|
|
373
|
+
(0, import_dom_query3.raf)(() => next?.focus());
|
|
517
374
|
},
|
|
518
375
|
focusPrevTab(ctx2) {
|
|
519
376
|
if (!ctx2.focusedValue)
|
|
520
377
|
return;
|
|
521
378
|
const prev = dom.getPrevEl(ctx2, ctx2.focusedValue);
|
|
522
|
-
raf(() => prev?.focus());
|
|
379
|
+
(0, import_dom_query3.raf)(() => prev?.focus());
|
|
523
380
|
},
|
|
524
381
|
setIndicatorRect(ctx2) {
|
|
525
|
-
nextTick(() => {
|
|
382
|
+
(0, import_dom_query3.nextTick)(() => {
|
|
526
383
|
if (!ctx2.isIndicatorRendered || !ctx2.value)
|
|
527
384
|
return;
|
|
528
385
|
ctx2.indicatorRect = dom.getRectById(ctx2, ctx2.value);
|
|
529
386
|
if (ctx2.hasMeasuredRect)
|
|
530
387
|
return;
|
|
531
|
-
nextTick(() => {
|
|
388
|
+
(0, import_dom_query3.nextTick)(() => {
|
|
532
389
|
ctx2.hasMeasuredRect = true;
|
|
533
390
|
});
|
|
534
391
|
});
|
|
@@ -550,12 +407,13 @@ function machine(userContext) {
|
|
|
550
407
|
ctx2.previousValues = pushUnique(Array.from(ctx2.previousValues), ctx2.value);
|
|
551
408
|
}
|
|
552
409
|
},
|
|
410
|
+
// if tab panel contains focusable elements, remove the tabindex attribute
|
|
553
411
|
setContentTabIndex(ctx2) {
|
|
554
|
-
raf(() => {
|
|
412
|
+
(0, import_dom_query3.raf)(() => {
|
|
555
413
|
const panel = dom.getActiveContentEl(ctx2);
|
|
556
414
|
if (!panel)
|
|
557
415
|
return;
|
|
558
|
-
const focusables = getFocusables(panel);
|
|
416
|
+
const focusables = (0, import_tabbable.getFocusables)(panel);
|
|
559
417
|
if (focusables.length > 0) {
|
|
560
418
|
panel.removeAttribute("tabindex");
|
|
561
419
|
} else {
|
package/dist/index.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
connect
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-5JW3YJ3I.mjs";
|
|
4
4
|
import {
|
|
5
5
|
anatomy
|
|
6
6
|
} from "./chunk-S2KW2DT4.mjs";
|
|
7
7
|
import {
|
|
8
8
|
machine
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-JG2VX4ST.mjs";
|
|
10
|
+
import "./chunk-5ZMNIWHF.mjs";
|
|
11
11
|
export {
|
|
12
12
|
anatomy,
|
|
13
13
|
connect,
|
package/dist/tabs.connect.d.ts
CHANGED
|
@@ -3,10 +3,25 @@ import { State, Send, TabProps } from './tabs.types.js';
|
|
|
3
3
|
import '@zag-js/core';
|
|
4
4
|
|
|
5
5
|
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
6
|
+
/**
|
|
7
|
+
* The current value of the tabs.
|
|
8
|
+
*/
|
|
6
9
|
value: string | null;
|
|
10
|
+
/**
|
|
11
|
+
* The value of the tab that is currently focused.
|
|
12
|
+
*/
|
|
7
13
|
focusedValue: string | null;
|
|
14
|
+
/**
|
|
15
|
+
* The previous values of the tabs in sequence of selection.
|
|
16
|
+
*/
|
|
8
17
|
previousValues: string[];
|
|
18
|
+
/**
|
|
19
|
+
* Sets the value of the tabs.
|
|
20
|
+
*/
|
|
9
21
|
setValue(value: string): void;
|
|
22
|
+
/**
|
|
23
|
+
* Clears the value of the tabs.
|
|
24
|
+
*/
|
|
10
25
|
clearValue(): void;
|
|
11
26
|
rootProps: T["element"];
|
|
12
27
|
tablistProps: T["element"];
|