1
- import React , { forwardRef , InputHTMLAttributes , ReactNode } from 'react'
1
+ import React , { forwardRef , InputHTMLAttributes , ReactNode , useEffect , useRef } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import classNames from 'classnames'
4
4
5
+ import { useForkedRef } from '../../utils/hooks'
5
6
import { Colors , Shapes } from '../Types'
6
7
7
8
import { CFormLabel } from './CFormLabel'
@@ -46,6 +47,10 @@ export interface CFormCheckProps extends InputHTMLAttributes<HTMLInputElement> {
46
47
* The id global attribute defines an identifier (ID) that must be unique in the whole document.
47
48
*/
48
49
id ?: string
50
+ /**
51
+ * Input Checkbox indeterminate Property.
52
+ */
53
+ indeterminate ?: boolean
49
54
/**
50
55
* Group checkboxes or radios on the same horizontal row by adding.
51
56
*/
@@ -70,9 +75,30 @@ export interface CFormCheckProps extends InputHTMLAttributes<HTMLInputElement> {
70
75
71
76
export const CFormCheck = forwardRef < HTMLInputElement , CFormCheckProps > (
72
77
(
73
- { className, button, hitArea, id, inline, invalid, label, type = 'checkbox' , valid, ...rest } ,
78
+ {
79
+ className,
80
+ button,
81
+ hitArea,
82
+ id,
83
+ indeterminate,
84
+ inline,
85
+ invalid,
86
+ label,
87
+ type = 'checkbox' ,
88
+ valid,
89
+ ...rest
90
+ } ,
74
91
ref ,
75
92
) => {
93
+ const inputRef = useRef < HTMLInputElement > ( null )
94
+ const forkedRef = useForkedRef ( ref , inputRef )
95
+
96
+ useEffect ( ( ) => {
97
+ if ( inputRef . current && indeterminate ) {
98
+ inputRef . current . indeterminate = indeterminate
99
+ }
100
+ } , [ indeterminate ] )
101
+
76
102
const _className = classNames (
77
103
'form-check' ,
78
104
{
@@ -102,7 +128,7 @@ export const CFormCheck = forwardRef<HTMLInputElement, CFormCheckProps>(
102
128
)
103
129
104
130
const formControl = ( ) => {
105
- return < input type = { type } className = { inputClassName } id = { id } { ...rest } ref = { ref } />
131
+ return < input type = { type } className = { inputClassName } id = { id } { ...rest } ref = { forkedRef } />
106
132
}
107
133
108
134
const formLabel = ( ) => {
@@ -141,6 +167,7 @@ CFormCheck.propTypes = {
141
167
className : PropTypes . string ,
142
168
hitArea : PropTypes . oneOf ( [ 'full' ] ) ,
143
169
id : PropTypes . string ,
170
+ indeterminate : PropTypes . bool ,
144
171
inline : PropTypes . bool ,
145
172
invalid : PropTypes . bool ,
146
173
label : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . node ] ) ,
0 commit comments