I'm trying to write a component to reuse and one of the varibles is the input type to render.
Currently, I have this:
type InputBaseProps = {
children?: ReactChild;
className?: string;
id: string;
label?: string;
name?: string;
onBlur: (event: ChangeEvent<HTMLInputElement>) => void;
onChange: (event: ChangeEvent<HTMLInputElement>) => void;
placeholder?: string;
style?: CSSProperties;
type: ????;
value?: string;
};
I want to allow only valid HTML types
, like the entire list defined here https://www.w3schools.com/tags/att_input_type.asp
Is there any simple way to do it?
import { HTMLInputTypeAttribute } from "react";
type InputBaseProps = {
type?: HTMLInputTypeAttribute
}
HTMLInputTypeAttribute
resolves to the ff:
type HTMLInputTypeAttribute = "number" | "search" | "button" | "time" | "image" | "text" | "checkbox" | "color" | "date" | "datetime-local" | "email" | "file" | "hidden" | "month" | "password" | "radio" | "range" | ... 5 more ... | (string & {})
Intellisense working fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With