@purpurds/text-field 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LICENSE.txt +5 -5
- package/dist/text-field.cjs.js +8 -8
- package/dist/text-field.cjs.js.map +1 -1
- package/dist/text-field.d.ts +2 -2
- package/dist/text-field.d.ts.map +1 -1
- package/dist/text-field.es.js +129 -125
- package/dist/text-field.es.js.map +1 -1
- package/package.json +7 -7
- package/src/text-field.tsx +12 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@purpurds/text-field",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"main": "./dist/text-field.cjs.js",
|
|
6
6
|
"types": "./dist/text-field.d.ts",
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"source": "src/text-field.tsx",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"classnames": "~2.5.0",
|
|
18
|
-
"@purpurds/field-error-text": "4.0.
|
|
19
|
-
"@purpurds/
|
|
20
|
-
"@purpurds/
|
|
21
|
-
"@purpurds/
|
|
22
|
-
"@purpurds/
|
|
23
|
-
"@purpurds/
|
|
18
|
+
"@purpurds/field-error-text": "4.0.1",
|
|
19
|
+
"@purpurds/icon": "4.0.1",
|
|
20
|
+
"@purpurds/label": "4.0.1",
|
|
21
|
+
"@purpurds/spinner": "4.0.1",
|
|
22
|
+
"@purpurds/tokens": "4.0.1",
|
|
23
|
+
"@purpurds/field-helper-text": "4.0.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@rushstack/eslint-patch": "~1.7.0",
|
package/src/text-field.tsx
CHANGED
|
@@ -14,8 +14,16 @@ import c from "classnames";
|
|
|
14
14
|
|
|
15
15
|
import styles from "./text-field.module.scss";
|
|
16
16
|
|
|
17
|
+
function setOrGenerateRandomId(id: string | undefined) {
|
|
18
|
+
if (typeof id === "undefined") {
|
|
19
|
+
const randomId = Math.random().toString(36).substring(2, 10); // Random alphanumeric string
|
|
20
|
+
return randomId;
|
|
21
|
+
}
|
|
22
|
+
return id;
|
|
23
|
+
}
|
|
24
|
+
|
|
17
25
|
export type TextFieldProps = ComponentPropsWithoutRef<"input"> & {
|
|
18
|
-
id: string;
|
|
26
|
+
id: string | undefined;
|
|
19
27
|
["data-testid"]?: string;
|
|
20
28
|
className?: string;
|
|
21
29
|
/**
|
|
@@ -84,9 +92,10 @@ const TextFieldComponent = (
|
|
|
84
92
|
}: TextFieldProps,
|
|
85
93
|
ref: ForwardedRef<HTMLInputElement>
|
|
86
94
|
) => {
|
|
95
|
+
const inputId = setOrGenerateRandomId(inputProps.id);
|
|
87
96
|
const getTestId = (name: string) => (dataTestId ? `${dataTestId}-${name}` : undefined);
|
|
88
97
|
const isValid = valid && !errorText;
|
|
89
|
-
const helperTextId = helperText ? `${
|
|
98
|
+
const helperTextId = helperText ? `${inputId}-helper-text` : undefined;
|
|
90
99
|
|
|
91
100
|
const startAdornments: ReactNode[] = [startAdornment].filter((adornment) => !!adornment);
|
|
92
101
|
|
|
@@ -124,7 +133,7 @@ const TextFieldComponent = (
|
|
|
124
133
|
<div className={c(className, styles[rootClassName])}>
|
|
125
134
|
{label && (
|
|
126
135
|
<Label
|
|
127
|
-
htmlFor={
|
|
136
|
+
htmlFor={inputId}
|
|
128
137
|
className={styles[`${rootClassName}__label`]}
|
|
129
138
|
data-testid={getTestId("label")}
|
|
130
139
|
disabled={inputProps.disabled}
|