@purpurds/text-field 4.0.1 → 4.1.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpurds/text-field",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
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.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"
18
+ "@purpurds/field-error-text": "4.1.0",
19
+ "@purpurds/icon": "4.1.0",
20
+ "@purpurds/field-helper-text": "4.1.0",
21
+ "@purpurds/label": "4.1.0",
22
+ "@purpurds/tokens": "4.1.0",
23
+ "@purpurds/spinner": "4.1.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@rushstack/eslint-patch": "~1.7.0",
@@ -38,6 +38,11 @@
38
38
  border-radius: var(--purpur-border-radius-sm);
39
39
  background: var(--purpur-color-background-primary);
40
40
 
41
+ &:has(:-internal-autofill-previewed),
42
+ &:has(:-internal-autofill-selected) {
43
+ background-color: var(--purpur-color-background-interactive-auto-fill) !important;
44
+ }
45
+
41
46
  &--disabled {
42
47
  background: var(--purpur-color-background-interactive-disabled);
43
48
  }
@@ -118,6 +123,12 @@
118
123
  }
119
124
  }
120
125
 
126
+ &:-internal-autofill-previewed,
127
+ &:-internal-autofill-selected {
128
+ box-shadow: inset 0 0 0 1px transparent,
129
+ inset 0 0 0 100px var(--purpur-color-background-interactive-auto-fill);
130
+ }
131
+
121
132
  &#{$inputRoot}--valid {
122
133
  ~ #{$root}__frame {
123
134
  border-color: var(--purpur-color-border-status-success);
@@ -4,6 +4,7 @@ import React, {
4
4
  forwardRef,
5
5
  HTMLInputTypeAttribute,
6
6
  ReactNode,
7
+ useId,
7
8
  } from "react";
8
9
  import { FieldErrorText } from "@purpurds/field-error-text";
9
10
  import { FieldHelperText } from "@purpurds/field-helper-text";
@@ -14,14 +15,6 @@ import c from "classnames";
14
15
 
15
16
  import styles from "./text-field.module.scss";
16
17
 
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
-
25
18
  export type TextFieldProps = ComponentPropsWithoutRef<"input"> & {
26
19
  id: string | undefined;
27
20
  ["data-testid"]?: string;
@@ -92,7 +85,8 @@ const TextFieldComponent = (
92
85
  }: TextFieldProps,
93
86
  ref: ForwardedRef<HTMLInputElement>
94
87
  ) => {
95
- const inputId = setOrGenerateRandomId(inputProps.id);
88
+ const randomId = useId();
89
+ const inputId = inputProps.id ?? randomId;
96
90
  const getTestId = (name: string) => (dataTestId ? `${dataTestId}-${name}` : undefined);
97
91
  const isValid = valid && !errorText;
98
92
  const helperTextId = helperText ? `${inputId}-helper-text` : undefined;
@@ -102,6 +96,7 @@ const TextFieldComponent = (
102
96
  const endAdornments: ReactNode[] = [
103
97
  loading && (
104
98
  <Spinner
99
+ key="spinner"
105
100
  variant={inputProps.disabled ? "disabled" : "primary"}
106
101
  size="xs"
107
102
  data-testid={getTestId("spinner")}
@@ -109,6 +104,7 @@ const TextFieldComponent = (
109
104
  ),
110
105
  isValid && (
111
106
  <Icon
107
+ key="valid-icon"
112
108
  data-testid={getTestId("valid-icon")}
113
109
  className={styles[`${rootClassName}__valid-icon`]}
114
110
  svg={checkCircleFilled}
@@ -153,6 +149,7 @@ const TextFieldComponent = (
153
149
  )}
154
150
  <input
155
151
  {...inputProps}
152
+ id={inputId}
156
153
  ref={ref}
157
154
  data-testid={getTestId("input")}
158
155
  aria-describedby={inputProps["aria-describedby"] || helperTextId}