@@ -13,39 +13,29 @@ import {
13
13
defineComponent ,
14
14
PropType ,
15
15
computed ,
16
- toRefs ,
17
- reactive ,
18
- ref ,
19
16
onMounted ,
20
17
Fragment ,
21
18
cloneVNode ,
22
19
watch ,
23
20
} from "vue"
24
- import {
25
- chakra ,
26
- useMultiStyleConfig ,
27
- } from "@chakra-ui/vue-system"
21
+ import { chakra , useMultiStyleConfig } from "@chakra-ui/vue-system"
28
22
import {
29
23
omitThemingProps ,
30
24
SystemStyleObject ,
31
25
ThemingProps ,
32
- SystemProps
26
+ SystemProps ,
33
27
} from "@chakra-ui/styled-system"
34
- import { SNAO , vueThemingProps , getValidChildren , } from "@chakra-ui/vue-utils"
35
- import {
36
- ComponentWithProps ,
37
- HTMLChakraProps ,
38
- } from "@chakra-ui/vue-system"
28
+ import { SNAO , vueThemingProps , getValidChildren } from "@chakra-ui/vue-utils"
29
+ import { HTMLChakraProps } from "@chakra-ui/vue-system"
39
30
import * as checkbox from "@zag-js/checkbox"
40
31
import { normalizeProps , useMachine , mergeProps } from "@zag-js/vue"
41
- import { useIds } from "@chakra-ui/vue-composables"
32
+ import { useId , useIds } from "@chakra-ui/vue-composables"
42
33
import { filterUndefined , mergeWith , pick } from "@chakra-ui/utils"
43
34
import {
44
35
CFormControlProviderContext ,
45
36
useFormControlContext ,
46
37
} from "@chakra-ui/c-form-control"
47
38
import { CheckboxIcon } from "./checkbox-icon"
48
- import { genId } from "@chakra-ui/vue-utils"
49
39
import { CheckboxGroupContext , useCheckboxGroupContext } from "./checkbox-group"
50
40
51
41
/**
@@ -119,8 +109,8 @@ export interface CCheckboxControlProps {
119
109
120
110
export interface CCheckboxProps
121
111
extends HTMLChakraProps < "input" > ,
122
- ThemingProps < "Checkbox" > ,
123
- CCheckboxControlProps {
112
+ ThemingProps < "Checkbox" > ,
113
+ CCheckboxControlProps {
124
114
/**
125
115
* The spacing between the checkbox and its label text
126
116
* @default 0.5rem
@@ -189,7 +179,7 @@ export const CCheckbox = defineComponent({
189
179
mergedProps as CFormControlProviderContext
190
180
)
191
181
192
- const id = genId ( )
182
+ const id = props . id || useId ( ) . value
193
183
const [ rootId , inputId , controlId , labelId ] = useIds (
194
184
`chakra-checkbox-${ id } ` ,
195
185
"root" ,
@@ -231,7 +221,7 @@ export const CCheckbox = defineComponent({
231
221
} )
232
222
233
223
const context = computed < checkbox . Context > ( ( ) => ( {
234
- id : id ,
224
+ id,
235
225
ids : {
236
226
root : rootId . value ,
237
227
input : inputId . value ,
@@ -243,12 +233,7 @@ export const CCheckbox = defineComponent({
243
233
244
234
const [ state , send ] = useMachine (
245
235
// @ts -ignore
246
- checkbox . machine ( {
247
- id : "chakra-ui-checkbox-machine" ,
248
- } ) ,
249
- {
250
- context,
251
- }
236
+ checkbox . machine ( { id, ...context . value } )
252
237
)
253
238
254
239
const api = computed ( ( ) =>
@@ -298,6 +283,16 @@ export const CCheckbox = defineComponent({
298
283
}
299
284
}
300
285
)
286
+
287
+ watch (
288
+ ( ) => props . isIndeterminate ,
289
+ ( value ) => {
290
+ if ( api . value && ! api . value . isReadOnly ) {
291
+ api . value . setIndeterminate ( value ! )
292
+ }
293
+ }
294
+ )
295
+
301
296
watch (
302
297
( ) => props . modelValue ,
303
298
( value ) => {
0 commit comments