From 5452644fc9d089bb7c7793fe2ff2234cbd4e7f32 Mon Sep 17 00:00:00 2001 From: Johnny Bouder Date: Tue, 10 Dec 2024 13:29:58 -0500 Subject: [PATCH] Fix issues. --- .../src/components/combo-box/combo-box.tsx | 2 +- .../src/components/form-group/form-group.tsx | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/comet-uswds/src/components/combo-box/combo-box.tsx b/packages/comet-uswds/src/components/combo-box/combo-box.tsx index e624a72b..45206b32 100644 --- a/packages/comet-uswds/src/components/combo-box/combo-box.tsx +++ b/packages/comet-uswds/src/components/combo-box/combo-box.tsx @@ -91,7 +91,7 @@ export const ComboBox = ({ const comboBoxAttributes: { className: string; - ref: RefObject; + ref: RefObject; 'data-placeholder'?: string; 'data-default-value'?: unknown; } = { diff --git a/packages/comet-uswds/src/components/form-group/form-group.tsx b/packages/comet-uswds/src/components/form-group/form-group.tsx index c449c14d..cd6891ad 100644 --- a/packages/comet-uswds/src/components/form-group/form-group.tsx +++ b/packages/comet-uswds/src/components/form-group/form-group.tsx @@ -81,10 +81,14 @@ export const FormGroup = ({ } // Get the id of the fieldControl element associated with the label - let fieldControlId = isValidElement(fieldControl) ? fieldControl.props.id : undefined; const fieldControlElement = isValidElement(fieldControl) - ? (fieldControl as React.ReactElement) + ? (fieldControl as React.ReactElement<{ + id?: string; + className?: string; + children?: ReactNode; + }>) : undefined; + let fieldControlId = fieldControlElement?.props?.id; let fieldControlWithProps = fieldControlElement; const fieldControlClass = fieldControlWithProps?.props.className; @@ -95,7 +99,11 @@ export const FormGroup = ({ fieldControlClass === 'usa-date-picker' ) { const children = fieldControlElement?.props.children; - fieldControlId = children?.props.id; + if ( + isValidElement(children) ? (children as React.ReactElement<{ id?: string }>).props.id : false + ) { + fieldControlId = (children as React.ReactElement<{ id?: string }>).props.id; + } } else { // Otherwise, we need to add aria-describedby to the fieldControl if (fieldControlElement) {