Skip to content

Commit 03482f3

Browse files
fix(clerk-js): Only apply id to FormFeedback when the type is error (clerk#4552)
1 parent 6468853 commit 03482f3

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

.changeset/itchy-cycles-sell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-js': patch
3+
---
4+
5+
Fixes issue where `FormFeedback` was rendering two elements with the same `id` attribute leading to invalid markup.

packages/clerk-js/src/ui/elements/FieldControl.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,12 @@ const FieldLabelRow = (props: PropsWithChildren) => {
154154
};
155155

156156
const FieldFeedback = (props: Pick<FormFeedbackProps, 'elementDescriptors' | 'center'>) => {
157-
const { fieldId, debouncedFeedback } = useFormField();
157+
const { fieldId, debouncedFeedback, errorMessageId } = useFormField();
158158

159159
return (
160160
<FormFeedback
161161
center={props.center}
162+
errorMessageId={errorMessageId}
162163
{...{
163164
...debouncedFeedback,
164165
elementDescriptors: props.elementDescriptors,

packages/clerk-js/src/ui/elements/FormControl.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@ export type FormFeedbackDescriptorsKeys = 'error' | 'warning' | 'info' | 'succes
7171
type Feedback = { feedback?: string; feedbackType?: FeedbackType; shouldEnter: boolean };
7272

7373
export type FormFeedbackProps = Partial<ReturnType<typeof useFormControlFeedback>['debounced'] & { id: FieldId }> & {
74+
errorMessageId?: string;
7475
elementDescriptors?: Partial<Record<FormFeedbackDescriptorsKeys, ElementDescriptor>>;
7576
center?: boolean;
7677
sx?: ThemableCssProp;
7778
};
7879

7980
export const FormFeedback = (props: FormFeedbackProps) => {
80-
const { id, elementDescriptors, sx, feedback, feedbackType = 'info', center = false } = props;
81+
const { id, elementDescriptors, sx, feedback, feedbackType = 'info', center = false, errorMessageId } = props;
8182
const feedbacksRef = useRef<{
8283
a?: Feedback;
8384
b?: Feedback;
@@ -142,6 +143,10 @@ export const FormFeedback = (props: FormFeedbackProps) => {
142143
return {
143144
elementDescriptor: descriptor,
144145
elementId: id ? descriptor?.setId?.(id) : undefined,
146+
// We only want the id applied when the feedback type is an error
147+
// to avoid having multiple elements in the dom with the same id attribute.
148+
// We also only have aria-describedby applied to the input when it is an error.
149+
id: type === 'error' ? errorMessageId : undefined,
145150
};
146151
};
147152

0 commit comments

Comments
 (0)