Merged in fix/restore-generated-id-inputs (pull request #1829)
fix: restore generated id for inputs Approved-by: Arvid Norlin
This commit is contained in:
@@ -2,6 +2,7 @@ import { cx } from "class-variance-authority"
|
|||||||
import {
|
import {
|
||||||
type ForwardedRef,
|
type ForwardedRef,
|
||||||
forwardRef,
|
forwardRef,
|
||||||
|
useId,
|
||||||
useImperativeHandle,
|
useImperativeHandle,
|
||||||
useRef,
|
useRef,
|
||||||
} from "react"
|
} from "react"
|
||||||
@@ -20,6 +21,12 @@ const AriaInputWithLabel = forwardRef(function AriaInputWithLabelComponent(
|
|||||||
) {
|
) {
|
||||||
const ref = useRef<HTMLInputElement>(null)
|
const ref = useRef<HTMLInputElement>(null)
|
||||||
|
|
||||||
|
// Unique id is required for multiple inputs of same name appearing multiple times
|
||||||
|
// on same page. This will inherited by parent label element.
|
||||||
|
// Shouldn't really be needed if we don't set id though.
|
||||||
|
const uniqueId = useId()
|
||||||
|
const inputId = `${uniqueId}-${props.name}`
|
||||||
|
|
||||||
useImperativeHandle(forwardedRef, () => ref.current as HTMLInputElement)
|
useImperativeHandle(forwardedRef, () => ref.current as HTMLInputElement)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -38,6 +45,7 @@ const AriaInputWithLabel = forwardRef(function AriaInputWithLabelComponent(
|
|||||||
{...props}
|
{...props}
|
||||||
className={cx(styles.input, props.className)}
|
className={cx(styles.input, props.className)}
|
||||||
ref={ref}
|
ref={ref}
|
||||||
|
id={inputId}
|
||||||
/>
|
/>
|
||||||
</Body>
|
</Body>
|
||||||
<Label required={props.required}>{label}</Label>
|
<Label required={props.required}>{label}</Label>
|
||||||
|
|||||||
Reference in New Issue
Block a user