Skip to content

Commit 08ec837

Browse files
authored
fix(ui): correctly thread through the autoComplete attribute from admin config to the text input (#12473)
We've already supported `autoComplete` on admin config for text fields but it wasn't being threaded through to the text input element so it couldn't be applied.
1 parent 505eaa2 commit 08ec837

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

packages/ui/src/elements/EmailAndUsername/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export function EmailAndUsernameFields(props: RenderEmailAndUsernameFieldsProps)
5252
<TextField
5353
field={{
5454
name: 'username',
55+
admin: {
56+
autoComplete: 'off',
57+
},
5558
label: t('authentication:username'),
5659
required: loginWithUsername && loginWithUsername.requireUsername,
5760
}}

packages/ui/src/fields/Text/Input.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const TextInput: React.FC<TextInputProps> = (props) => {
2525
description,
2626
Error,
2727
hasMany,
28+
htmlAttributes,
2829
inputRef,
2930
Label,
3031
label,
@@ -158,6 +159,7 @@ export const TextInput: React.FC<TextInputProps> = (props) => {
158159
ref={inputRef}
159160
type="text"
160161
value={value || ''}
162+
{...(htmlAttributes ?? {})}
161163
/>
162164
)}
163165
{AfterInput}

packages/ui/src/fields/Text/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const TextFieldComponent: TextFieldClientComponent = (props) => {
2121
const {
2222
field,
2323
field: {
24-
admin: { className, description, placeholder, rtl } = {},
24+
admin: { autoComplete, className, description, placeholder, rtl } = {},
2525
hasMany,
2626
label,
2727
localized,
@@ -123,6 +123,9 @@ const TextFieldComponent: TextFieldClientComponent = (props) => {
123123
description={description}
124124
Error={Error}
125125
hasMany={hasMany}
126+
htmlAttributes={{
127+
autoComplete: autoComplete || undefined,
128+
}}
126129
inputRef={inputRef}
127130
Label={Label}
128131
label={label}

packages/ui/src/fields/Text/types.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { StaticDescription, StaticLabel } from 'payload'
2-
import type { ChangeEvent } from 'react'
2+
import type { ChangeEvent, JSX } from 'react'
33
import type React from 'react'
44

55
import type { Option, ReactSelectAdapterProps } from '../../elements/ReactSelect/types.js'
@@ -21,6 +21,9 @@ export type TextInputProps = {
2121
readonly Description?: React.ReactNode
2222
readonly description?: StaticDescription
2323
readonly Error?: React.ReactNode
24+
readonly htmlAttributes?: {
25+
autoComplete?: JSX.IntrinsicElements['input']['autoComplete']
26+
}
2427
readonly inputRef?: React.RefObject<HTMLInputElement>
2528
readonly Label?: React.ReactNode
2629
readonly label?: StaticLabel

0 commit comments

Comments
 (0)