@@ -9,55 +9,41 @@ import {
9
9
toggleControlShareStyles ,
10
10
toggleLabelShareStyles ,
11
11
} from "../../shared/styles" ;
12
+ import type { CheckedValueProps } from "../../shared/types" ;
12
13
import { ariaAttr , tx } from "../../utils" ;
13
14
import { type CheckboxBaseProps , useCheckboxGroup } from "./checkbox-group-context" ;
14
15
15
- export type CheckboxProps = CheckboxBaseProps & {
16
- /**
17
- * 可控值
18
- */
19
- checked ?: boolean ;
20
-
21
- /**
22
- * 默认值
23
- * @default false
24
- */
25
- defaultChecked ?: boolean ;
26
-
27
- /**
28
- * onChange 回调
29
- */
30
- onChange ?: ( checked : boolean ) => void ;
31
-
32
- /**
33
- * 值
34
- */
35
- value ?: string | number ;
36
-
37
- /**
38
- * 部分选中
39
- * @default false
40
- */
41
- indeterminate ?: boolean ;
42
-
43
- /**
44
- * 是否无效
45
- * @default false
46
- */
47
- invalid ?: boolean ;
48
-
49
- /**
50
- * 间距
51
- * @default "0.5em"
52
- */
53
- spacing ?: string | number ;
54
- } ;
16
+ export type CheckboxProps = CheckedValueProps &
17
+ CheckboxBaseProps & {
18
+ /**
19
+ * 是否无效
20
+ * @default false
21
+ */
22
+ invalid ?: boolean ;
23
+
24
+ /**
25
+ * 值
26
+ */
27
+ value ?: string | number ;
28
+
29
+ /**
30
+ * 部分选中
31
+ * @default false
32
+ */
33
+ indeterminate ?: boolean ;
34
+
35
+ /**
36
+ * 间距
37
+ * @default "0.5em"
38
+ */
39
+ spacing ?: string | number ;
40
+ } ;
55
41
56
42
export const Checkbox = ( props : PrimitiveProps < "input" , CheckboxProps , "role" | "type" > ) => {
57
43
const group = useCheckboxGroup ( true ) ;
58
44
59
45
const {
60
- name = group ?. name ,
46
+ name,
61
47
size = group ?. size || "md" ,
62
48
color = group ?. color || "primary" ,
63
49
disabled = group ?. disabled || false ,
@@ -116,6 +102,8 @@ export const Checkbox = (props: PrimitiveProps<"input", CheckboxProps, "role" |
116
102
const colorStyle = binaryColorShareStyles [ color ] ;
117
103
const labelSizeStyle = inputTextShareStyles [ size ] ;
118
104
105
+ const htmlName = group ?. name ? `${ group . name } []` : name ;
106
+
119
107
return (
120
108
< label
121
109
style = {
@@ -128,7 +116,7 @@ export const Checkbox = (props: PrimitiveProps<"input", CheckboxProps, "role" |
128
116
>
129
117
< input
130
118
ref = { refs }
131
- name = { name }
119
+ name = { htmlName }
132
120
className = { "peer sr-only" }
133
121
value = { value }
134
122
type = "checkbox"
0 commit comments