GitHub

TextInput

The <TextInput /> element represents a text field for inputting single- or multiline text.

import { View, Text, TextInput } from '@react-pdf/renderer';

const field = { height: 18, borderWidth: 1, borderColor: '#c9c2b6' };
const label = { fontSize: 9, color: '#3e3e3e', marginBottom: 4 };

const NameField = () => (
  <View>
    <Text style={label}>Full name</Text>
    <TextInput name="name" value="Ada Lovelace" style={field} />
  </View>
);
Show preview

Valid props

Prop nameDescriptionTypeDefault
alignDefines the alignment of textStringleft
multilineDefines if the user is allowed to input more than one line of textBooleanfalse
passwordIf set to true the text will be masked with e. g. *Booleanfalse
noSpellIf set to true tells the pdf viewer to not spellcheck the textBooleanfalse
formatDefines the format the textinput should be formatted toTextInputFormattingundefined
fontSizeDefines the font size for the text input. Set to 0 for auto-sizeNumberundefined
maxLengthDefines the maximum number of charactersNumberundefined

See also Common Form Attributes

TextInputFormatting

format is a definition how the value shall be formatted by the viewer. Take into account that not all viewers support this feature because it involves javascript execution.

Prop nameDescriptionTypeDefault
typeDefines the alignment of textTextInputFormatTypeundefined
paramDefines a format for certain typesStringundefined
nDecDefines the number of places after the decimal pointNumberundefined
sepCommaDefines if the seperator shall be a comma or notBooleanfalse
negStyleDefines style for negative numbersStringundefined
currencyDefines the symbol to be placed as currency signStringundefined
currencyPrependIf set to true the currency sign is prependedBooleanfalse

TextInputFormatType

type prop can take one of the following values.

ValueDescription
dateExpects the param prop to be a valid date format.
timeExpects the param prop to be a valid time format.
percentUses the props nDec, sepComma, negStyle, currency, currencyPrepend.
numberUses the props nDec, sepComma, negStyle, currency, currencyPrepend.
zipFormats for the zip-code standard
zipPlus4Formats for the zip+4 standard
phoneFormats for a phone number
ssnFormats for a ssn number

For deeper knowledge into the formatting you might want to look into the pdfkit doc and into the API Reference for Forms Page 119.

On this page