Skip to content

Instantly share code, notes, and snippets.

@pkayokay
Created October 23, 2024 22:05
Show Gist options
  • Save pkayokay/1970ca6655b880a431ed6d8cf62c3f39 to your computer and use it in GitHub Desktop.
Save pkayokay/1970ca6655b880a431ed6d8cf62c3f39 to your computer and use it in GitHub Desktop.
Example of a text input in React
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