Skip to main content

Text Input

Basic

Let's say you want to create a simple textinput. So let's take an example how you do it, check it out below.

create a file at app/user/page.tsx

app/user/page.tsx
<AFormInput
name={'username'}
type={'text'}
onChange={(value) => onInputChange(value)}
onBlur={() => setcheckBox([])}
defaultValue={'2'}
disabled={false}
readonly={false}
placeholder={'Username'}
validation={'required'}
/>

The above code will render TextInput like this.

Basic TextInput

Props

NameTypeRequiredDescription
namestringYesname of a input.
type'text' , 'number' , 'email' , 'password' , 'url'YesThis chapter describes the different types for the HTML <input> tag element.
readonlybooleanNoit specifies that an input field is read-only. A read-only input field cannot be modified (however, a user can tab to it, highlight it, and copy the text from it).
disabledbooleanNoA disabled input element is unusable and un-clickable.
placeholderbooleanNoThe placeholder attribute specifies a short hint that describes the expected value of an input field.
maxlengthnumberNoThe maxlength attribute defines the maximum number of characters.
defaultValuestringNoThe default value is the value specified in the HTML value attribute.
autocompletebooleanNoThe autocomplete attribute specifies whether or not an input field should have autocomplete enabled.
iconstringYesIcon inside the input element tag are used widely to add icons on the webpages.
iconPosition"prefix" , "postfix"NoYou can use two values top and left along with the position property to move an HTML element anywhere in the HTML document.

Events

NameTypeRequiredDescription
onChange(value: string) => voidNoThe onchange event occurs when the value of an HTML element is changed.
onBlur() => voidNoThe onblur event occurs when an HTML element loses focus. The onblur event is often used on input fields. The onblur event is often used with form validation (when the user leaves a form field).