Text input
The TextInput
component is a component that is used to get user information in a single-line text field. It is rendered for multiple fields and may be used by other new fields in the future.
Used by
- Short Answer
- URL
const TextInput = React.memo(function TextInput(props) {return <input {...props} />;});const components = {TextInput}// ...and then elsewhere<FormiumForm components={components} />
If you want to change the rendering behavior to be different depending which field it is being used for,
you can do so by looking at its type
prop like so:
const TextInput = React.memo(function TextInput({type, ...props}) {switch (type) {// Short Answercase 'text':return <input type={type} {...props} className="my-text-input" />;case 'email':return <input type={type} {...props} className="my-email-input" />;// URL fieldcase 'url':return <input type={type} {...props} className="my-url-input" />;// Always specify a fallback.default:// You might want to warn if you get this far...// console.warn('<TextInput /> doesn\'t have an implementation for specified type of `${type}`.')return <input type={type} {...props} />;}});const components = {TextInput}// ...and then elsewhere<FormiumForm components={components} />
Props
In addition to its own props, it supports all valid props for HTML <input>
elements and proxies them to that element in the DOM; the most common ones are detailed below.
interface TextInputProps extends BaseInputProps
@formium/react
Props | Description |
---|---|
disabled | |
id | |
name | |
onBlur | React.FormEventHandler Event handler invoked when input is blurred. Required Inherited from BaseInputProps.onBlur |
onChange | React.FormEventHandler Change event handler. Use event.target.value for new value. Required Inherited from BaseInputProps.onChange |
onFocus | React.FormEventHandler Event handler invoked when input is focused. Required Inherited from BaseInputProps.onFocus |
placeholder | |
required | |
type | string HTML Required |
value |
Was this page helpful?
Build forms, without the tears.
Resources
hello@formium.io — Copyright © 2020 Formium, Inc. All rights reserved.