mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
refactor(ui): properly set autocomplete props (#3175)
This commit is contained in:
parent
6858f3c8dc
commit
d5bac1560a
8 changed files with 17 additions and 7 deletions
|
@ -62,11 +62,11 @@ const SmartInputField = (
|
|||
|
||||
return (
|
||||
<InputField
|
||||
{...getInputHtmlProps(enabledTypes, identifierType)}
|
||||
{...rest}
|
||||
ref={innerRef}
|
||||
isSuffixFocusVisible={Boolean(inputValue)}
|
||||
isPrefixVisible={identifierType === SignInIdentifier.Phone}
|
||||
{...getInputHtmlProps(enabledTypes, identifierType)}
|
||||
value={inputValue}
|
||||
prefix={conditional(
|
||||
isPhoneEnabled && (
|
||||
|
|
|
@ -16,6 +16,7 @@ describe('Smart Input Field Util Methods', () => {
|
|||
expect(props.pattern).toBe('[0-9]*');
|
||||
expect(props.inputMode).toBe('numeric');
|
||||
expect(props.placeholder).toBe('input.phone_number');
|
||||
expect(props.autoComplete).toBe('tel');
|
||||
});
|
||||
|
||||
it('Should return correct html props for email', () => {
|
||||
|
@ -23,18 +24,21 @@ describe('Smart Input Field Util Methods', () => {
|
|||
expect(props.type).toBe('email');
|
||||
expect(props.inputMode).toBe('email');
|
||||
expect(props.placeholder).toBe('input.email');
|
||||
expect(props.autoComplete).toBe('email');
|
||||
});
|
||||
|
||||
it('Should return correct html props for username', () => {
|
||||
const props = getInputHtmlProps([SignInIdentifier.Username], SignInIdentifier.Username);
|
||||
expect(props.type).toBe('text');
|
||||
expect(props.placeholder).toBe('input.username');
|
||||
expect(props.autoComplete).toBe('username');
|
||||
});
|
||||
|
||||
it('Should return correct html props for username email or phone', () => {
|
||||
const props = getInputHtmlProps(enabledTypes, SignInIdentifier.Username);
|
||||
expect(props.type).toBe('text');
|
||||
expect(props.placeholder).toBe('input.username / input.email / input.phone_number');
|
||||
expect(props.autoComplete).toBe('username email tel');
|
||||
});
|
||||
|
||||
it('Should return correct html props for email or phone', () => {
|
||||
|
@ -44,6 +48,7 @@ describe('Smart Input Field Util Methods', () => {
|
|||
);
|
||||
expect(props.type).toBe('text');
|
||||
expect(props.placeholder).toBe('input.email / input.phone_number');
|
||||
expect(props.autoComplete).toBe('email tel');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -10,12 +10,16 @@ import type { IdentifierInputType } from './use-smart-input-field';
|
|||
export const getInputHtmlProps = (
|
||||
enabledTypes: IdentifierInputType[],
|
||||
currentType?: IdentifierInputType
|
||||
): Pick<HTMLProps<HTMLInputElement>, 'type' | 'pattern' | 'inputMode' | 'placeholder'> => {
|
||||
): Pick<
|
||||
HTMLProps<HTMLInputElement>,
|
||||
'type' | 'pattern' | 'inputMode' | 'placeholder' | 'autoComplete'
|
||||
> => {
|
||||
if (currentType === SignInIdentifier.Phone && enabledTypes.length === 1) {
|
||||
return {
|
||||
type: 'tel',
|
||||
pattern: '[0-9]*',
|
||||
inputMode: 'numeric',
|
||||
autoComplete: 'tel',
|
||||
placeholder: i18next.t<'translation', TFuncKey>('input.phone_number'),
|
||||
};
|
||||
}
|
||||
|
@ -24,12 +28,16 @@ export const getInputHtmlProps = (
|
|||
return {
|
||||
type: 'email',
|
||||
inputMode: 'email',
|
||||
autoComplete: 'email',
|
||||
placeholder: i18next.t<'translation', TFuncKey>('input.email'),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'text',
|
||||
autoComplete: enabledTypes
|
||||
.map((type) => (type === SignInIdentifier.Phone ? 'tel' : type))
|
||||
.join(' '),
|
||||
placeholder: enabledTypes
|
||||
.map((type) => i18next.t<'translation', TFuncKey>(identifierInputPlaceholderMap[type]))
|
||||
.join(' / '),
|
||||
|
|
|
@ -101,7 +101,7 @@ const IdentifierProfileForm = ({
|
|||
}}
|
||||
render={({ field }) => (
|
||||
<SmartInputField
|
||||
autoComplete="new-identifier"
|
||||
autoComplete="off"
|
||||
autoFocus={autoFocus}
|
||||
className={styles.inputField}
|
||||
{...field}
|
||||
|
|
|
@ -102,7 +102,6 @@ const ForgotPasswordForm = ({
|
|||
}}
|
||||
render={({ field }) => (
|
||||
<SmartInputField
|
||||
autoComplete="identifier"
|
||||
autoFocus={autoFocus}
|
||||
className={styles.inputField}
|
||||
{...field}
|
||||
|
|
|
@ -89,7 +89,7 @@ const IdentifierRegisterForm = ({ className, autoFocus, signUpMethods }: Props)
|
|||
}}
|
||||
render={({ field }) => (
|
||||
<SmartInputField
|
||||
autoComplete="new-identifier"
|
||||
autoComplete="off"
|
||||
autoFocus={autoFocus}
|
||||
className={styles.inputField}
|
||||
{...field}
|
||||
|
|
|
@ -87,7 +87,6 @@ const IdentifierSignInForm = ({ className, autoFocus, signInMethods }: Props) =>
|
|||
}}
|
||||
render={({ field }) => (
|
||||
<SmartInputField
|
||||
autoComplete="identifier"
|
||||
autoFocus={autoFocus}
|
||||
className={styles.inputField}
|
||||
{...field}
|
||||
|
|
|
@ -96,7 +96,6 @@ const PasswordSignInForm = ({ className, autoFocus, signInMethods }: Props) => {
|
|||
}}
|
||||
render={({ field }) => (
|
||||
<SmartInputField
|
||||
autoComplete="identifier"
|
||||
autoFocus={autoFocus}
|
||||
className={styles.inputField}
|
||||
{...field}
|
||||
|
|
Loading…
Reference in a new issue