+
+
+ {labelChild ? (
+ /*
+ Placing the caption text and validation text in the provides a better user
+ experience for more screenreaders.
+
+ Reference: https://blog.tenon.io/accessible-validation-of-checkbox-and-radiobutton-groups/
+ */
+
+ {slots.label}
+ {slots.caption}
+ {React.isValidElement(slots.validation) && slots.validation.props.children && (
+ {slots.validation.props.children}
+ )}
+
+ ) : (
+ /*
+ If CheckboxOrRadioGroup.Label wasn't passed as a child, we don't render a
+ but we still want to render a caption
+ */
+ slots.caption
+ )}
+
+
+ {React.Children.toArray(rest).filter(child => React.isValidElement(child))}
+
+
+ {validationChild && (
+
+ aria-hidden={Boolean(labelChild)}
+ show
+ >
+ {slots.validation}
+
+ )}
+
+
+ )
+ }
+ return (
+
+
+
+ {labelChild ? (
+ /*
+ Placing the caption text and validation text in the provides a better user
+ experience for more screenreaders.
+
+ Reference: https://blog.tenon.io/accessible-validation-of-checkbox-and-radiobutton-groups/
+ */
+
+ {slots.label}
+ {slots.caption}
+ {React.isValidElement(slots.validation) && slots.validation.props.children && (
+ {slots.validation.props.children}
+ )}
+
+ ) : (
+ /*
+ If CheckboxOrRadioGroup.Label wasn't passed as a child, we don't render a
+ but we still want to render a caption
+ */
+ slots.caption
+ )}
+
+
+ {React.Children.toArray(rest).filter(child => React.isValidElement(child))}
+
+
+ {validationChild && (
+
+ aria-hidden={Boolean(labelChild)}
+ show
+ >
+ {slots.validation}
+
+ )}
+
+
+ )
+ }
+
return (
{labelChild ? (
diff --git a/packages/react/src/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupCaption.tsx b/packages/react/src/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupCaption.tsx
index 683e32c002d..4e74d4fc6bb 100644
--- a/packages/react/src/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupCaption.tsx
+++ b/packages/react/src/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupCaption.tsx
@@ -2,11 +2,33 @@ import React from 'react'
import Text from '../../../Text'
import type {SxProp} from '../../../sx'
import CheckboxOrRadioGroupContext from './CheckboxOrRadioGroupContext'
+import classes from './CheckboxOrRadioGroup.module.css'
+import {CSS_MODULES_FLAG} from './FeatureFlag'
+import {useFeatureFlag} from '../../../FeatureFlags'
+import {clsx} from 'clsx'
-const CheckboxOrRadioGroupCaption: React.FC> = ({children, sx}) => {
+type CheckboxOrRadioGroupCaptionProps = React.PropsWithChildren & {className?: string}
+
+const CheckboxOrRadioGroupCaption: React.FC = ({className, children, sx}) => {
const {disabled, captionId} = React.useContext(CheckboxOrRadioGroupContext)
+ const enabled = useFeatureFlag(CSS_MODULES_FLAG)
+ if (enabled) {
+ if (sx) {
+ return (
+
+ {children}
+
+ )
+ }
+ return (
+
+ {children}
+
+ )
+ }
+
return (
-
+
{children}
)
diff --git a/packages/react/src/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupLabel.tsx b/packages/react/src/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupLabel.tsx
index 2f5b43ea0f7..ee79f687cc1 100644
--- a/packages/react/src/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupLabel.tsx
+++ b/packages/react/src/internal/components/CheckboxOrRadioGroup/CheckboxOrRadioGroupLabel.tsx
@@ -3,8 +3,15 @@ import Box from '../../../Box'
import VisuallyHidden from '../../../_VisuallyHidden'
import type {SxProp} from '../../../sx'
import CheckboxOrRadioGroupContext from './CheckboxOrRadioGroupContext'
+import {CSS_MODULES_FLAG} from './FeatureFlag'
+import {useFeatureFlag} from '../../../FeatureFlags'
+import classes from './CheckboxOrRadioGroup.module.css'
+import {Stack} from '../../../Stack'
+import {clsx} from 'clsx'
export type CheckboxOrRadioGroupLabelProps = {
+ /** Class name for custom styling */
+ className?: string
/**
* Whether to visually hide the fieldset legend
*/
@@ -13,12 +20,57 @@ export type CheckboxOrRadioGroupLabelProps = {
const CheckboxOrRadioGroupLabel: React.FC> = ({
children,
+ className,
visuallyHidden = false,
sx,
}) => {
const {required, disabled} = React.useContext(CheckboxOrRadioGroupContext)
+ const enabled = useFeatureFlag(CSS_MODULES_FLAG)
+
+ if (enabled) {
+ if (sx) {
+ return (
+
+ {required ? (
+
+ {children}
+ *
+
+ ) : (
+ children
+ )}
+
+ )
+ }
+
+ return (
+
+ {required ? (
+
+ {children}
+ *
+
+ ) : (
+ children
+ )}
+
+ )
+ }
+
return (