@@ -6,7 +6,7 @@ import React, {
66 ReactNode ,
77} from 'react' ;
88import classnames from 'classnames' ;
9- import { FormElement , FormElementProps } from './FormElement' ;
9+ import { FormElement } from './FormElement' ;
1010import { CheckboxGroupContext , CheckboxValueType } from './CheckboxGroup' ;
1111
1212/**
@@ -15,7 +15,6 @@ import { CheckboxGroupContext, CheckboxValueType } from './CheckboxGroup';
1515export type CheckboxProps = {
1616 label ?: string ;
1717 required ?: boolean ;
18- error ?: FormElementProps [ 'error' ] ;
1918 cols ?: number ;
2019 name ?: string ;
2120 value ?: CheckboxValueType ;
@@ -33,10 +32,10 @@ export type CheckboxProps = {
3332export const Checkbox : FC < CheckboxProps > = ( props ) => {
3433 const {
3534 type, // eslint-disable-line @typescript-eslint/no-unused-vars
35+ id,
3636 className,
3737 label,
3838 required,
39- error,
4039 cols,
4140 tooltip,
4241 tooltipIcon,
@@ -45,10 +44,12 @@ export const Checkbox: FC<CheckboxProps> = (props) => {
4544 children,
4645 ...rprops
4746 } = props ;
48- const { grouped } = useContext ( CheckboxGroupContext ) ;
47+
48+ const { grouped, error, errorId } = useContext ( CheckboxGroupContext ) ;
4949 const formElemProps = {
5050 required,
5151 error,
52+ errorId,
5253 cols,
5354 tooltip,
5455 tooltipIcon,
@@ -57,8 +58,14 @@ export const Checkbox: FC<CheckboxProps> = (props) => {
5758 const checkClassNames = classnames ( className , 'slds-checkbox' ) ;
5859 const check = (
5960 < div className = { checkClassNames } >
60- < input ref = { inputRef } type = 'checkbox' { ...rprops } />
61- < label className = 'slds-checkbox__label' >
61+ < input
62+ ref = { inputRef }
63+ type = 'checkbox'
64+ { ...rprops }
65+ id = { id }
66+ aria-describedby = { error ? errorId : undefined }
67+ />
68+ < label className = 'slds-checkbox__label' htmlFor = { id } >
6269 < span className = 'slds-checkbox_faux' />
6370 < span className = 'slds-form-element__label' > { label || children } </ span >
6471 </ label >
0 commit comments