@zag-js/radio-group 1.8.1 → 1.9.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 +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +12 -17
- package/dist/index.mjs +13 -18
- package/package.json +7 -8
package/dist/index.d.mts
CHANGED
|
@@ -92,10 +92,6 @@ interface PrivateContext {
|
|
|
92
92
|
* Whether the radio group's fieldset is disabled
|
|
93
93
|
*/
|
|
94
94
|
fieldsetDisabled: boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Whether the radio group is in focus
|
|
97
|
-
*/
|
|
98
|
-
focusVisible: boolean;
|
|
99
95
|
/**
|
|
100
96
|
* Whether the radio group is in server-side rendering
|
|
101
97
|
*/
|
|
@@ -153,6 +149,10 @@ interface ItemState {
|
|
|
153
149
|
* Whether the item is focused
|
|
154
150
|
*/
|
|
155
151
|
focused: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Whether the item is focused and the focus is visible
|
|
154
|
+
*/
|
|
155
|
+
focusVisible: boolean;
|
|
156
156
|
/**
|
|
157
157
|
* Whether the item is hovered
|
|
158
158
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -92,10 +92,6 @@ interface PrivateContext {
|
|
|
92
92
|
* Whether the radio group's fieldset is disabled
|
|
93
93
|
*/
|
|
94
94
|
fieldsetDisabled: boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Whether the radio group is in focus
|
|
97
|
-
*/
|
|
98
|
-
focusVisible: boolean;
|
|
99
95
|
/**
|
|
100
96
|
* Whether the radio group is in server-side rendering
|
|
101
97
|
*/
|
|
@@ -153,6 +149,10 @@ interface ItemState {
|
|
|
153
149
|
* Whether the item is focused
|
|
154
150
|
*/
|
|
155
151
|
focused: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* Whether the item is focused and the focus is visible
|
|
154
|
+
*/
|
|
155
|
+
focusVisible: boolean;
|
|
156
156
|
/**
|
|
157
157
|
* Whether the item is hovered
|
|
158
158
|
*/
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,6 @@ var anatomy$1 = require('@zag-js/anatomy');
|
|
|
4
4
|
var domQuery = require('@zag-js/dom-query');
|
|
5
5
|
var focusVisible = require('@zag-js/focus-visible');
|
|
6
6
|
var core = require('@zag-js/core');
|
|
7
|
-
var elementRect = require('@zag-js/element-rect');
|
|
8
7
|
var utils = require('@zag-js/utils');
|
|
9
8
|
var types = require('@zag-js/types');
|
|
10
9
|
|
|
@@ -58,12 +57,15 @@ function connect(service, normalize) {
|
|
|
58
57
|
const groupDisabled = computed("isDisabled");
|
|
59
58
|
const readOnly = prop("readOnly");
|
|
60
59
|
function getItemState(props2) {
|
|
60
|
+
const focused = context.get("focusedValue") === props2.value;
|
|
61
|
+
const focusVisible$1 = focused && focusVisible.isFocusVisible();
|
|
61
62
|
return {
|
|
62
63
|
value: props2.value,
|
|
63
64
|
invalid: !!props2.invalid,
|
|
64
65
|
disabled: !!props2.disabled || groupDisabled,
|
|
65
66
|
checked: context.get("value") === props2.value,
|
|
66
|
-
focused
|
|
67
|
+
focused,
|
|
68
|
+
focusVisible: focusVisible$1,
|
|
67
69
|
hovered: context.get("hoveredValue") === props2.value,
|
|
68
70
|
active: context.get("activeValue") === props2.value
|
|
69
71
|
};
|
|
@@ -72,7 +74,7 @@ function connect(service, normalize) {
|
|
|
72
74
|
const itemState = getItemState(props2);
|
|
73
75
|
return {
|
|
74
76
|
"data-focus": domQuery.dataAttr(itemState.focused),
|
|
75
|
-
"data-focus-visible": domQuery.dataAttr(itemState.
|
|
77
|
+
"data-focus-visible": domQuery.dataAttr(itemState.focusVisible),
|
|
76
78
|
"data-disabled": domQuery.dataAttr(itemState.disabled),
|
|
77
79
|
"data-readonly": domQuery.dataAttr(readOnly),
|
|
78
80
|
"data-state": itemState.checked ? "checked" : "unchecked",
|
|
@@ -194,11 +196,10 @@ function connect(service, normalize) {
|
|
|
194
196
|
}
|
|
195
197
|
},
|
|
196
198
|
onBlur() {
|
|
197
|
-
send({ type: "SET_FOCUSED", value: null, focused: false
|
|
199
|
+
send({ type: "SET_FOCUSED", value: null, focused: false });
|
|
198
200
|
},
|
|
199
201
|
onFocus() {
|
|
200
|
-
|
|
201
|
-
send({ type: "SET_FOCUSED", value: props2.value, focused: true, focusVisible: focusVisible$1 });
|
|
202
|
+
send({ type: "SET_FOCUSED", value: props2.value, focused: true });
|
|
202
203
|
},
|
|
203
204
|
onKeyDown(event) {
|
|
204
205
|
if (event.defaultPrevented) return;
|
|
@@ -281,9 +282,6 @@ var machine = core.createMachine({
|
|
|
281
282
|
fieldsetDisabled: bindable(() => ({
|
|
282
283
|
defaultValue: false
|
|
283
284
|
})),
|
|
284
|
-
focusVisible: bindable(() => ({
|
|
285
|
-
defaultValue: false
|
|
286
|
-
})),
|
|
287
285
|
ssr: bindable(() => ({
|
|
288
286
|
defaultValue: true
|
|
289
287
|
}))
|
|
@@ -359,7 +357,6 @@ var machine = core.createMachine({
|
|
|
359
357
|
},
|
|
360
358
|
setFocused({ context, event }) {
|
|
361
359
|
context.set("focusedValue", event.value);
|
|
362
|
-
context.set("focusVisible", event.focusVisible);
|
|
363
360
|
},
|
|
364
361
|
syncInputElements({ context, scope }) {
|
|
365
362
|
const inputs = getInputEls(scope);
|
|
@@ -382,18 +379,16 @@ var machine = core.createMachine({
|
|
|
382
379
|
const value = context.get("value");
|
|
383
380
|
const radioEl = getRadioEl(scope, value);
|
|
384
381
|
if (value == null || !radioEl) {
|
|
382
|
+
context.set("canIndicatorTransition", false);
|
|
385
383
|
context.set("indicatorRect", {});
|
|
386
384
|
return;
|
|
387
385
|
}
|
|
388
|
-
const indicatorCleanup =
|
|
389
|
-
|
|
386
|
+
const indicatorCleanup = domQuery.trackElementRect([radioEl], {
|
|
387
|
+
measure(el) {
|
|
390
388
|
return getOffsetRect(el);
|
|
391
389
|
},
|
|
392
|
-
|
|
393
|
-
context.set("indicatorRect", resolveRect(
|
|
394
|
-
domQuery.nextTick(() => {
|
|
395
|
-
context.set("canIndicatorTransition", false);
|
|
396
|
-
});
|
|
390
|
+
onEntry({ rects }) {
|
|
391
|
+
context.set("indicatorRect", resolveRect(rects[0]));
|
|
397
392
|
}
|
|
398
393
|
});
|
|
399
394
|
refs.set("indicatorCleanup", indicatorCleanup);
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { createAnatomy } from '@zag-js/anatomy';
|
|
2
|
-
import { dispatchInputCheckedEvent,
|
|
2
|
+
import { dispatchInputCheckedEvent, trackElementRect, trackFormControl, queryAll, dataAttr, visuallyHiddenStyle, isSafari } from '@zag-js/dom-query';
|
|
3
3
|
import { trackFocusVisible, isFocusVisible } from '@zag-js/focus-visible';
|
|
4
4
|
import { createGuards, createMachine } from '@zag-js/core';
|
|
5
|
-
import { trackElementRect } from '@zag-js/element-rect';
|
|
6
5
|
import { isString, createSplitProps } from '@zag-js/utils';
|
|
7
6
|
import { createProps } from '@zag-js/types';
|
|
8
7
|
|
|
@@ -56,12 +55,15 @@ function connect(service, normalize) {
|
|
|
56
55
|
const groupDisabled = computed("isDisabled");
|
|
57
56
|
const readOnly = prop("readOnly");
|
|
58
57
|
function getItemState(props2) {
|
|
58
|
+
const focused = context.get("focusedValue") === props2.value;
|
|
59
|
+
const focusVisible = focused && isFocusVisible();
|
|
59
60
|
return {
|
|
60
61
|
value: props2.value,
|
|
61
62
|
invalid: !!props2.invalid,
|
|
62
63
|
disabled: !!props2.disabled || groupDisabled,
|
|
63
64
|
checked: context.get("value") === props2.value,
|
|
64
|
-
focused
|
|
65
|
+
focused,
|
|
66
|
+
focusVisible,
|
|
65
67
|
hovered: context.get("hoveredValue") === props2.value,
|
|
66
68
|
active: context.get("activeValue") === props2.value
|
|
67
69
|
};
|
|
@@ -70,7 +72,7 @@ function connect(service, normalize) {
|
|
|
70
72
|
const itemState = getItemState(props2);
|
|
71
73
|
return {
|
|
72
74
|
"data-focus": dataAttr(itemState.focused),
|
|
73
|
-
"data-focus-visible": dataAttr(itemState.
|
|
75
|
+
"data-focus-visible": dataAttr(itemState.focusVisible),
|
|
74
76
|
"data-disabled": dataAttr(itemState.disabled),
|
|
75
77
|
"data-readonly": dataAttr(readOnly),
|
|
76
78
|
"data-state": itemState.checked ? "checked" : "unchecked",
|
|
@@ -192,11 +194,10 @@ function connect(service, normalize) {
|
|
|
192
194
|
}
|
|
193
195
|
},
|
|
194
196
|
onBlur() {
|
|
195
|
-
send({ type: "SET_FOCUSED", value: null, focused: false
|
|
197
|
+
send({ type: "SET_FOCUSED", value: null, focused: false });
|
|
196
198
|
},
|
|
197
199
|
onFocus() {
|
|
198
|
-
|
|
199
|
-
send({ type: "SET_FOCUSED", value: props2.value, focused: true, focusVisible });
|
|
200
|
+
send({ type: "SET_FOCUSED", value: props2.value, focused: true });
|
|
200
201
|
},
|
|
201
202
|
onKeyDown(event) {
|
|
202
203
|
if (event.defaultPrevented) return;
|
|
@@ -279,9 +280,6 @@ var machine = createMachine({
|
|
|
279
280
|
fieldsetDisabled: bindable(() => ({
|
|
280
281
|
defaultValue: false
|
|
281
282
|
})),
|
|
282
|
-
focusVisible: bindable(() => ({
|
|
283
|
-
defaultValue: false
|
|
284
|
-
})),
|
|
285
283
|
ssr: bindable(() => ({
|
|
286
284
|
defaultValue: true
|
|
287
285
|
}))
|
|
@@ -357,7 +355,6 @@ var machine = createMachine({
|
|
|
357
355
|
},
|
|
358
356
|
setFocused({ context, event }) {
|
|
359
357
|
context.set("focusedValue", event.value);
|
|
360
|
-
context.set("focusVisible", event.focusVisible);
|
|
361
358
|
},
|
|
362
359
|
syncInputElements({ context, scope }) {
|
|
363
360
|
const inputs = getInputEls(scope);
|
|
@@ -380,18 +377,16 @@ var machine = createMachine({
|
|
|
380
377
|
const value = context.get("value");
|
|
381
378
|
const radioEl = getRadioEl(scope, value);
|
|
382
379
|
if (value == null || !radioEl) {
|
|
380
|
+
context.set("canIndicatorTransition", false);
|
|
383
381
|
context.set("indicatorRect", {});
|
|
384
382
|
return;
|
|
385
383
|
}
|
|
386
|
-
const indicatorCleanup = trackElementRect(radioEl, {
|
|
387
|
-
|
|
384
|
+
const indicatorCleanup = trackElementRect([radioEl], {
|
|
385
|
+
measure(el) {
|
|
388
386
|
return getOffsetRect(el);
|
|
389
387
|
},
|
|
390
|
-
|
|
391
|
-
context.set("indicatorRect", resolveRect(
|
|
392
|
-
nextTick(() => {
|
|
393
|
-
context.set("canIndicatorTransition", false);
|
|
394
|
-
});
|
|
388
|
+
onEntry({ rects }) {
|
|
389
|
+
context.set("indicatorRect", resolveRect(rects[0]));
|
|
395
390
|
}
|
|
396
391
|
});
|
|
397
392
|
refs.set("indicatorCleanup", indicatorCleanup);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/radio-group",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Core logic for the radio group widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -27,13 +27,12 @@
|
|
|
27
27
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@zag-js/
|
|
31
|
-
"@zag-js/
|
|
32
|
-
"@zag-js/
|
|
33
|
-
"@zag-js/
|
|
34
|
-
"@zag-js/
|
|
35
|
-
"@zag-js/
|
|
36
|
-
"@zag-js/types": "1.8.1"
|
|
30
|
+
"@zag-js/dom-query": "1.9.0",
|
|
31
|
+
"@zag-js/anatomy": "1.9.0",
|
|
32
|
+
"@zag-js/focus-visible": "1.9.0",
|
|
33
|
+
"@zag-js/utils": "1.9.0",
|
|
34
|
+
"@zag-js/core": "1.9.0",
|
|
35
|
+
"@zag-js/types": "1.9.0"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
38
|
"clean-package": "2.2.0"
|