Skip to content

Commit 15acca9

Browse files
committed
fix(form): handle htmlFor prop fallback in FormLabel
Ensure FormLabel correctly falls back to formItemId when htmlFor is not provided, maintaining backward compatibility while allowing explicit htmlFor overrides.
1 parent df63b8c commit 15acca9

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

  • packages/ui-react/src/components/ui/form

packages/ui-react/src/components/ui/form/form.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export function FormFieldContext(props: FormFieldContextProps) {
211211
export function FormLabel(props: InferProps<"label">) {
212212
const fieldContextValues = useStrictFormFieldContext();
213213

214-
const { children, htmlFor = fieldContextValues.formItemId, ...restOfProps } = props;
214+
const { children, htmlFor, ...restOfProps } = props;
215215

216216
const { isDisabled, isInvalid } = useLaxFormFieldState({ name: fieldContextValues.name });
217217

@@ -222,7 +222,7 @@ export function FormLabel(props: InferProps<"label">) {
222222
data-slot="form-label"
223223
data-disabled={dataAttr(isDisabled)}
224224
data-invalid={dataAttr(isInvalid)}
225-
htmlFor={htmlFor}
225+
htmlFor={Object.hasOwn(props, "htmlFor") ? htmlFor : fieldContextValues.formItemId}
226226
{...restOfProps}
227227
>
228228
{children}

0 commit comments

Comments
 (0)