1- import React , { forwardRef , InputHTMLAttributes , ReactNode } from 'react'
1+ import React , { forwardRef , InputHTMLAttributes , ReactNode , useEffect , useRef } from 'react'
22import PropTypes from 'prop-types'
33import classNames from 'classnames'
44
5+ import { useForkedRef } from '../../utils/hooks'
56import { Colors , Shapes } from '../Types'
67
78import { CFormLabel } from './CFormLabel'
@@ -46,6 +47,10 @@ export interface CFormCheckProps extends InputHTMLAttributes<HTMLInputElement> {
4647 * The id global attribute defines an identifier (ID) that must be unique in the whole document.
4748 */
4849 id ?: string
50+ /**
51+ * Input Checkbox indeterminate Property.
52+ */
53+ indeterminate ?: boolean
4954 /**
5055 * Group checkboxes or radios on the same horizontal row by adding.
5156 */
@@ -70,9 +75,30 @@ export interface CFormCheckProps extends InputHTMLAttributes<HTMLInputElement> {
7075
7176export const CFormCheck = forwardRef < HTMLInputElement , CFormCheckProps > (
7277 (
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+ } ,
7491 ref ,
7592 ) => {
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+
76102 const _className = classNames (
77103 'form-check' ,
78104 {
@@ -102,7 +128,7 @@ export const CFormCheck = forwardRef<HTMLInputElement, CFormCheckProps>(
102128 )
103129
104130 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 } />
106132 }
107133
108134 const formLabel = ( ) => {
@@ -141,6 +167,7 @@ CFormCheck.propTypes = {
141167 className : PropTypes . string ,
142168 hitArea : PropTypes . oneOf ( [ 'full' ] ) ,
143169 id : PropTypes . string ,
170+ indeterminate : PropTypes . bool ,
144171 inline : PropTypes . bool ,
145172 invalid : PropTypes . bool ,
146173 label : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . node ] ) ,
0 commit comments