Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextFieldRoot can't be set as email type when there's a password type input in a form #631

Open
WaningJupiter opened this issue Nov 19, 2024 · 3 comments

Comments

@WaningJupiter
Copy link

WaningJupiter commented Nov 19, 2024

I'm using TextFieldRoot to create a login form with React hook form. I'm using the TextFieldRoot inside the Tabs theme component.

I realized that in browsers (Firefox and Safari), the <TextField.Root> is always treated as a field of password, however, I specified its type and its name.

The react hook form register works correctly. I tested the code separately, it turns out that if the form only contains a <TextField.Root type="email">, it behaves as expected. However, when both <TextField.Root type="email"> and <TextField.Root type="password"> are present in the same form, the first email input field is also mistakenly treated as a password input by the browser.

Here's my code:

<Tabs.Root defaultValue="login">
	<Tabs.List>
		...triggers
	</Tabs.List>

..
<Tabs.Content value="login">
<form onSubmit={handleLoginSubmit((data) => console.log(data))} action="#" method="post">
          <fieldset className="grid gap-8 max-w-md" name="login">
         <TextInput
            id="email"
            label="Email"
            placeholder="your mail"
            type="email"
            register={{
             ...register("email", {
            required: "Please enter your mail",
            }), }}
            errorMessage={errors.email?.message}
       /> // The textinput doesn't work as email, see more in the component below 
         //Without the PasswordInput, the first input will be treated as email correctly 
       <PasswordInput
                      id="password"
                      label="Mot de passe"
                      placeholder="Votre mot de passe"
                      name="password"
                    />
       </fieldset >
</form>
</Tabs.Content>
                      ...
type TextInputProps = {
  id: string;
  label: string;
  placeholder: string;
  type: "email"|"text";
  register?: UseFormRegisterReturn;
  errorMessage?:string;
};

export function TextInput({ id, label, placeholder, type = "email", register, errorMessage }: TextInputProps) {
  return (
    <Box className="flex-1">
      <label htmlFor={id} className="text-sm font-medium text-gray-700">
        {label}
      </label>
      <TextField.Root {...register} id={id} placeholder={placeholder} size="3" type={type}/>
      {errorMessage && <ErrorMessage>{errorMessage}</ErrorMessage>}
    </Box>
  );
}
@WaningJupiter WaningJupiter changed the title Can't we set TextFieldRoot as email type ? TextFieldRoot can't be set as email type when there's a password type input in a form Nov 19, 2024
@WaningJupiter
Copy link
Author

I think it's more a behavior of browser rather than <TextField.Root>, I tested with native without component, the same problem.

@ijxy
Copy link

ijxy commented Jan 15, 2025

What do you mean by "mistakenly treated as a password input by the browser"?

As far as I can tell, the browser is correctly rendering the HTML with the expected properties. For example:

<Section>
  <form
    action={(formData) => {
      const data = Object.fromEntries(formData.entries());
      console.log(data);
    }}
  >
    <TextField.Root name="email" type="email" />
    <TextField.Root name="password" type="password" />
    <Button type="submit">Submit</Button>
  </form>
</Section>
<div class="rt-TextFieldRoot rt-r-size-2 rt-variant-surface">
  <input spellcheck="false" class="rt-reset rt-TextFieldInput" type="email" name="email">
</div>
<div class="rt-TextFieldRoot rt-r-size-2 rt-variant-surface">
  <input spellcheck="false" class="rt-reset rt-TextFieldInput" type="password" name="password">
</div>
<button data-accent-color="" type="submit" class="rt-reset rt-BaseButton rt-r-size-2 rt-variant-solid rt-Button">Submit</button>

Chrome:
image

Safari:
image

@WaningJupiter
Copy link
Author

Hello, @ijxy
sorry, i didn't make it very clear.
When I keeped click at the field of email (not the first time of click), the browser gave me a :"Manage your passwords" block.It will take me to the window where we find all the passwords remebered by the browsers. But I set it very clearly it's a email field

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants