From 2ee00ed919d534188f3ac4d694eaf7b1053a3394 Mon Sep 17 00:00:00 2001 From: garronej Date: Mon, 1 Nov 2021 22:28:53 +0100 Subject: [PATCH] Better autoComplete typings --- src/lib/components/RegisterUserProfile.tsx | 15 +----- src/lib/getKcContext/KcContextBase.ts | 56 +++++++++++++++++++++- src/lib/useFormValidationSlice.tsx | 2 + 3 files changed, 58 insertions(+), 15 deletions(-) diff --git a/src/lib/components/RegisterUserProfile.tsx b/src/lib/components/RegisterUserProfile.tsx index 43172bb7..ab39cee8 100644 --- a/src/lib/components/RegisterUserProfile.tsx +++ b/src/lib/components/RegisterUserProfile.tsx @@ -149,15 +149,6 @@ const UserProfileFormFields = memo(({ kcContext, onIsFormSubmittableValueChange,
{ - switch (attribute.name) { - case "password-confirm": - case "password": - return "new-password"; - default: - return undefined; - } - })()} type={(() => { switch (attribute.name) { case "password-confirm": @@ -174,11 +165,7 @@ const UserProfileFormFields = memo(({ kcContext, onIsFormSubmittableValueChange, className={cx(props.kcInputClass)} aria-invalid={displayableErrors.length !== 0} disabled={attribute.readOnly} - {...(attribute.autocomplete === undefined - ? {} - : { - "autoComplete": attribute.autocomplete, - })} + autoComplete={attribute.autocomplete} onBlur={onBlurFactory(attribute.name)} /> {displayableErrors.length !== 0 && ( diff --git a/src/lib/getKcContext/KcContextBase.ts b/src/lib/getKcContext/KcContextBase.ts index 7c89fae0..49ea3e7b 100644 --- a/src/lib/getKcContext/KcContextBase.ts +++ b/src/lib/getKcContext/KcContextBase.ts @@ -217,10 +217,64 @@ export type Attribute = { groupDisplayHeader?: string; groupDisplayDescription?: string; readOnly: boolean; - autocomplete?: string; validators: Validators; annotations: Record; groupAnnotations: Record; + 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<{ diff --git a/src/lib/useFormValidationSlice.tsx b/src/lib/useFormValidationSlice.tsx index af8ad984..83c0b8fc 100644 --- a/src/lib/useFormValidationSlice.tsx +++ b/src/lib/useFormValidationSlice.tsx @@ -312,6 +312,7 @@ export function useFormValidationSlice(params: { "validators": passwordValidators, "annotations": {}, "groupAnnotations": {}, + "autocomplete": "new-password", }), id({ "name": "password-confirm", @@ -328,6 +329,7 @@ export function useFormValidationSlice(params: { }, "annotations": {}, "groupAnnotations": {}, + "autocomplete": "new-password", }), ]), ],