Skip to content

Commit 176b699

Browse files
m-maillotddecrulle
andauthored
feat: add a native label props on Input (#365)
* feat: add a native label props on Input * import type as type and add few doc --------- Co-authored-by: Dylan Decrulle <dylan.decrulle@outlook.fr>
1 parent 6910034 commit 176b699

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/Input.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React, {
22
memo,
33
forwardRef,
4-
ReactNode,
54
useId,
6-
type InputHTMLAttributes,
7-
type TextareaHTMLAttributes,
5+
type CSSProperties,
86
type DetailedHTMLProps,
9-
type CSSProperties
7+
type InputHTMLAttributes,
8+
type LabelHTMLAttributes,
9+
type ReactNode,
10+
type TextareaHTMLAttributes
1011
} from "react";
1112
import { symToStr } from "tsafe/symToStr";
1213
import { assert } from "tsafe/assert";
@@ -50,6 +51,11 @@ export namespace InputProps {
5051
InputHTMLAttributes<HTMLInputElement>,
5152
HTMLInputElement
5253
>;
54+
/** Props forwarded to the underlying <label /> element */
55+
nativeLabelProps?: DetailedHTMLProps<
56+
LabelHTMLAttributes<HTMLInputElement>,
57+
HTMLInputElement
58+
>;
5359

5460
nativeTextAreaProps?: never;
5561
};
@@ -62,6 +68,11 @@ export namespace InputProps {
6268
TextareaHTMLAttributes<HTMLTextAreaElement>,
6369
HTMLTextAreaElement
6470
>;
71+
/** Props forwarded to the underlying <label /> element */
72+
nativeLabelProps?: DetailedHTMLProps<
73+
LabelHTMLAttributes<HTMLTextAreaElement>,
74+
HTMLTextAreaElement
75+
>;
6576

6677
nativeInputProps?: never;
6778
};
@@ -89,6 +100,7 @@ export const Input = memo(
89100
nativeInputProps,
90101
addon,
91102
action,
103+
nativeLabelProps,
92104
...rest
93105
} = props;
94106

@@ -137,6 +149,7 @@ export const Input = memo(
137149
<label
138150
className={cx(fr.cx("fr-label", hideLabel && "fr-sr-only"), classes.label)}
139151
htmlFor={inputId}
152+
{...(nativeLabelProps as {})}
140153
>
141154
{label}
142155
{hintText !== undefined && <span className="fr-hint-text">{hintText}</span>}

0 commit comments

Comments
 (0)