Better autoComplete typings

This commit is contained in:
garronej
2021-11-01 22:28:53 +01:00
parent cbfc271da5
commit 2ee00ed919
3 changed files with 58 additions and 15 deletions

View File

@ -149,15 +149,6 @@ const UserProfileFormFields = memo(({ kcContext, onIsFormSubmittableValueChange,
</div> </div>
<div className={cx(props.kcInputWrapperClass)}> <div className={cx(props.kcInputWrapperClass)}>
<input <input
autoComplete={(() => {
switch (attribute.name) {
case "password-confirm":
case "password":
return "new-password";
default:
return undefined;
}
})()}
type={(() => { type={(() => {
switch (attribute.name) { switch (attribute.name) {
case "password-confirm": case "password-confirm":
@ -174,11 +165,7 @@ const UserProfileFormFields = memo(({ kcContext, onIsFormSubmittableValueChange,
className={cx(props.kcInputClass)} className={cx(props.kcInputClass)}
aria-invalid={displayableErrors.length !== 0} aria-invalid={displayableErrors.length !== 0}
disabled={attribute.readOnly} disabled={attribute.readOnly}
{...(attribute.autocomplete === undefined autoComplete={attribute.autocomplete}
? {}
: {
"autoComplete": attribute.autocomplete,
})}
onBlur={onBlurFactory(attribute.name)} onBlur={onBlurFactory(attribute.name)}
/> />
{displayableErrors.length !== 0 && ( {displayableErrors.length !== 0 && (

View File

@ -217,10 +217,64 @@ export type Attribute = {
groupDisplayHeader?: string; groupDisplayHeader?: string;
groupDisplayDescription?: string; groupDisplayDescription?: string;
readOnly: boolean; readOnly: boolean;
autocomplete?: string;
validators: Validators; validators: Validators;
annotations: Record<string, string>; annotations: Record<string, string>;
groupAnnotations: Record<string, string>; groupAnnotations: Record<string, string>;
autocomplete?:
| "on"
| "off"
| "name"
| "honorific-prefix"
| "given-name"
| "additional-name"
| "family-name"
| "honorific-suffix"
| "nickname"
| "email"
| "username"
| "new-password"
| "current-password"
| "one-time-code"
| "organization-title"
| "organization"
| "street-address"
| "address-line1"
| "address-line2"
| "address-line3"
| "address-level4"
| "address-level3"
| "address-level2"
| "address-level1"
| "country"
| "country-name"
| "postal-code"
| "cc-name"
| "cc-given-name"
| "cc-additional-name"
| "cc-family-name"
| "cc-number"
| "cc-exp"
| "cc-exp-month"
| "cc-exp-year"
| "cc-csc"
| "cc-type"
| "transaction-currency"
| "transaction-amount"
| "language"
| "bday"
| "bday-day"
| "bday-month"
| "bday-year"
| "sex"
| "tel"
| "tel-country-code"
| "tel-national"
| "tel-area-code"
| "tel-local"
| "tel-extension"
| "impp"
| "url"
| "photo";
}; };
export type Validators = Partial<{ export type Validators = Partial<{

View File

@ -312,6 +312,7 @@ export function useFormValidationSlice(params: {
"validators": passwordValidators, "validators": passwordValidators,
"annotations": {}, "annotations": {},
"groupAnnotations": {}, "groupAnnotations": {},
"autocomplete": "new-password",
}), }),
id<Attribute>({ id<Attribute>({
"name": "password-confirm", "name": "password-confirm",
@ -328,6 +329,7 @@ export function useFormValidationSlice(params: {
}, },
"annotations": {}, "annotations": {},
"groupAnnotations": {}, "groupAnnotations": {},
"autocomplete": "new-password",
}), }),
]), ]),
], ],