Created
October 23, 2024 22:05
-
-
Save pkayokay/1970ca6655b880a431ed6d8cf62c3f39 to your computer and use it in GitHub Desktop.
Example of a text input in React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const TextInput = ({ | |
autoComplete, | |
description, | |
id, | |
label, | |
onChange, | |
placeholder, | |
required, | |
value, | |
}: { | |
autoComplete?: React.HTMLInputAutoCompleteAttribute | undefined; | |
description?: string; | |
id: string; | |
label: string; | |
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void; | |
placeholder?: string; | |
required?: boolean; | |
value?: string; | |
}) => { | |
return ( | |
<> | |
<label htmlFor={id} className="label-class"> | |
{label} | |
</label> | |
<input | |
id={id} | |
name={id} | |
type="text" | |
className="input-class" | |
value={value} | |
onChange={onChange} | |
placeholder={placeholder} | |
required={required} | |
autoComplete={autoComplete} | |
/> | |
{description && ( | |
<small className="description-class">{description}</small> | |
)} | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment