Fixed password required not showing

This commit is contained in:
Lucas Oliveira 2023-08-11 15:25:24 -03:00
commit 0f015cadc7
3 changed files with 57 additions and 27 deletions

View file

@ -1,3 +1,4 @@
import * as Form from "@radix-ui/react-form";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { InputComponentType } from "../../types/components"; import { InputComponentType } from "../../types/components";
import { classNames } from "../../utils/utils"; import { classNames } from "../../utils/utils";
@ -7,6 +8,8 @@ export default function InputComponent({
value, value,
onChange, onChange,
disabled, disabled,
required = false,
isForm = false,
password, password,
editNode = false, editNode = false,
placeholder = "Type something...", placeholder = "Type something...",
@ -23,21 +26,47 @@ export default function InputComponent({
return ( return (
<div className="relative w-full"> <div className="relative w-full">
<Input {isForm ? (
value={value} <Form.Control asChild>
disabled={disabled} <Input
className={classNames( value={value}
password && !pwdVisible && value !== "" ? " text-clip password " : "", disabled={disabled}
editNode ? " input-edit-node " : "", required={required}
password && editNode ? "pr-8" : "", className={classNames(
password && !editNode ? "pr-10" : "", password && !pwdVisible && value !== ""
className ? " text-clip password "
)} : "",
placeholder={password && editNode ? "Key" : placeholder} editNode ? " input-edit-node " : "",
onChange={(e) => { password && editNode ? "pr-8" : "",
onChange(e.target.value); password && !editNode ? "pr-10" : "",
}} className
/> )}
placeholder={password && editNode ? "Key" : placeholder}
onChange={(e) => {
onChange(e.target.value);
}}
/>
</Form.Control>
) : (
<Input
value={value}
disabled={disabled}
required={required}
className={classNames(
password && !pwdVisible && value !== ""
? " text-clip password "
: "",
editNode ? " input-edit-node " : "",
password && editNode ? "pr-8" : "",
password && !editNode ? "pr-10" : "",
className
)}
placeholder={password && editNode ? "Key" : placeholder}
onChange={(e) => {
onChange(e.target.value);
}}
/>
)}
{password && ( {password && (
<button <button
className={classNames( className={classNames(

View file

@ -81,18 +81,17 @@ export default function SignUp(): JSX.Element {
<Form.Label className="data-[invalid]:label-invalid"> <Form.Label className="data-[invalid]:label-invalid">
Password <span className="font-medium text-destructive">*</span> Password <span className="font-medium text-destructive">*</span>
</Form.Label> </Form.Label>
<InputComponent
<Form.Control asChild> onChange={(value) => {
<InputComponent handleInput({ target: { name: "password", value } });
onChange={(value) => { }}
handleInput({ target: { name: "password", value } }); value={password}
}} isForm
value={password} password={true}
password={true} required
placeholder="Password" placeholder="Password"
className="w-full" className="w-full"
/> />
</Form.Control>
<Form.Message className="field-invalid" match="valueMissing"> <Form.Message className="field-invalid" match="valueMissing">
Please enter a password Please enter a password

View file

@ -7,6 +7,8 @@ export type InputComponentType = {
disabled?: boolean; disabled?: boolean;
onChange: (value: string) => void; onChange: (value: string) => void;
password: boolean; password: boolean;
required?: boolean;
isForm?: boolean;
editNode?: boolean; editNode?: boolean;
onChangePass?: (value: boolean | boolean) => void; onChangePass?: (value: boolean | boolean) => void;
showPass?: boolean; showPass?: boolean;