Skip to main content

NitroInput props

NitroInput takes every View prop (style, testID, accessibilityLabel, …) plus the ones below. All are optional.

A test in the package fails when this page misses a prop the component declares, so what is listed here is what the component takes. Every entry links to itself.

Text and value​

valuestring

The text to show (controlled). The native side formats and shows what the user types on its own; the prop is applied when it changes to something other than what the field already shows, so echoing onChangeText back into state never fights the user. A value carrying a stale mostRecentEventCount is ignored, as TextInput ignores it.

The initial text (uncontrolled).

placeholderstringDefault ''

Shown while the field is empty. With transition="reflow" the first character reflows it away. In 'number' mode '0' reads well.

placeholderTextColorColorValueDefault platform

Colour of the placeholder.

maxLengthnumberDefault unlimited

'text' mode: the most characters accepted.

editablebooleanDefault true

Whether the user can edit the field.

readOnlybooleanDefault false

Alias of editable={false}, as in React Native.

Mode​

One prop picks how the field edits. It is separate from inputMode and keyboardType, which only pick the keyboard. See An amount field and A masked field.

mode'text' | 'number' | 'mask'Default 'text'

'text' is a plain field. 'number' formats natively as you type: grouping separators, one decimal separator, up to fractionDigits decimals, a currency prefix / suffix; the value comes out of onChangeValue and getValue(). 'mask' applies the fixed pattern in mask.

Number mode​

fractionDigitsnumberDefault 2

Most digits allowed after the decimal separator; a keystroke past it is rejected. 0 disables the decimal.

maxIntegerDigitsnumberDefault 15

Most integer digits accepted.

groupingSeparatorstringDefault ','

Inserted between every three integer digits. '' disables grouping.

decimalSeparatorstringDefault '.'

Placed between integer and fraction digits. Whatever the keyboard's decimal key produces (. or ,) is accepted as it.

signPlacement'beforeAffix' | 'afterAffix'Default 'beforeAffix'

Where a negative amount's sign sits relative to prefix: -$1,234.56, or $-1,234.56 with 'afterAffix'. Only the reflow honours it; a plain field's affixes are accessory views outside the text, so it is always 'afterAffix' there. See Negative amounts.

Mask mode​

maskstringDefault ''

The pattern, e.g. '+1 ([000]) [000]-[0000]'. [0] mandatory digit, [9] optional digit, [A] mandatory letter, [a] optional letter, [_] mandatory alphanumeric, [-] optional alphanumeric, […] an unbounded run of the preceding type. {…} is a fixed block whose characters count towards the extracted value; a literal outside brackets is shown but not extracted. \\ escapes. An invalid pattern leaves the field unmasked rather than breaking it.

maskNotations{ character: string; characterSet: string }[]Default []

Your own slot characters beyond the built-in ones: the character that stands for the slot in the mask, and every character it accepts.

maskAutocompletebooleanDefault true

Fill in constants as the caret reaches them. Only with the caret at the end, so editing mid-value does not fight you.

maskAutoSkipbooleanDefault false

Backspace walks back over autocompleted constants.

keepPlaceholderbooleanDefault false

Keep the rest of the placeholder visible, greyed, after what has been typed: with placeholder="1234 5678 9012", typing 12345 shows 1234 5 and then 678 9012. Without a placeholder the mask itself is shown, its empty slots as maskSlotPlaceholder: +1 (212) ___-____. When one of maskAffinityFormats has taken over, its own tail is shown, since the placeholder was written for mask.

maskSlotPlaceholderstringDefault '_' with keepPlaceholder, else ''

The character each empty slot shows in the kept placeholder and in onChangeMask's tail. Empty: the slot's own notation character (0, a, -).

maskAffinityFormatsstring[]Default []

More patterns the text may take, e.g. the Amex 4-6-5 grouping beside a 4-4-4-4 mask: ['{34}[00] [000000] [00000]', '{37}[00] [000000] [00000]']. Every edit is masked with each, and the best by maskAffinityStrategy is kept. mask wins ties; once another format is showing, it keeps a tie too, so the field does not flip back and forth as you type.

maskAffinityStrategy'wholeString' | 'prefix' | 'capacity' | 'extractedValueCapacity'Default 'wholeString'

How the best of maskAffinityFormats is chosen: the format that accepts the most characters and inserts the fewest, the one whose output starts most like what was typed, or the fullest format that still holds all of the text / all of its value characters.

maskTextCase'none' | 'upper' | 'lower'Default 'none'

Uppercase or lowercase letters as they are typed or pasted, without moving the caret: a BIC, an IBAN or a licence plate typed in lowercase comes out right.

maskCharacterMapRecord<string, string>Default {}

Characters replaced before masking, one character each: { 'С': 'C' } turns a Cyrillic look-alike into a Latin letter, { ',': '.' } lets a comma through to a dot-decimal mask. An empty replacement drops the character.

Affixes​

Static text around the field's text, drawn at their own sizes. See An amount field.

prefixstringDefault ''

Drawn before the text, e.g. '$'.

suffixstringDefault ''

Drawn after the text, e.g. ' USD'.

prefixFontSizenumberDefault fontSize

Font size of prefix, e.g. a smaller currency symbol.

suffixFontSizenumberDefault fontSize

Font size of suffix.

affixAlign'baseline' | 'center' | 'top' | 'bottom'Default 'baseline'

How prefix and suffix line up with the text: 'top' pins glyph tops, 'bottom' the bottom of the ink, 'baseline' shares the baseline, 'center' centres.

prefixAlign'baseline' | 'center' | 'top' | 'bottom'Default affixAlign

Alignment of prefix only.

suffixAlign'baseline' | 'center' | 'top' | 'bottom'Default affixAlign

Alignment of suffix only.

letterSpacingnumberDefault 0

Points added after every glyph, like Text's letterSpacing (negative tightens). A smaller prefix or suffix gets it in proportion to its size.

prefixSpacing, suffixSpacingnumberDefault the letter spacing

Points between the prefix and the text, and between the text and the suffix, in place of the letter spacing there.

Points an affix is moved down after its alignment places it (negative: up), for a symbol that sits a little off every preset.

formatNumberFormat

A NumberFormat the amount follows: its prefix and suffix (the currency where the locale puts it), grouping and decimal separators, fraction digits and where the sign goes. Sets mode to 'number' unless it is given; the individual props override what it says.

Frame and label​

An outlined or filled box with a floating label, drawn natively. See Frames.

variant'none' | 'outlined' | 'filled'Default 'none'

'outlined' strokes a rounded rectangle notched around the floating label; the notch is a real hole in the path, so whatever is behind the field shows through. 'filled' tints the box. 'none' leaves the border to style.

labelstringDefault ''

The floating label. Needs a variant other than 'none'. Also the field's accessible name when nothing else supplies one.

labelBehavior'float' | 'always'Default 'float'

'float' sits inline while the field is empty and unfocused and floats once it is focused or has text; 'always' stays floated.

labelColorColorValueDefault placeholderTextColor

Label colour at rest.

labelFocusedColorColorValueDefault focusedStrokeColor

Label colour while focused.

labelFontSizenumberDefault from fontSize

Label size when floated, in points.

strokeColorColorValueDefault hairline grey

Outline colour.

focusedStrokeColorColorValueDefault strokeColor

Outline colour while focused.

strokeWidthnumberDefault 1

Outline width in points, doubled while focused.

cornerRadiusnumberDefault 8

Corner radius of the frame.

fillColorColorValue

'filled': the box tint.

Typography​

Resolved the way Text resolves its style.

fontSizenumberDefault 32

Font size in points.

fontWeightTextStyle['fontWeight']Default 'normal'

Font weight, as Text's.

fontFamilystringDefault system

Font family, as Text's; bundled and expo-font fonts work.

colorColorValueDefault label colour

Text colour.

lineHeightnumberDefault the font's

Height of the line box in points, in the CSS sense: the total height a line occupies. Unlike TextInput, a line height tighter than the font is centred correctly too, and it applies to single-line and reflowing fields as well as wrapped ones.

allowFontScalingbooleanDefault false

Scale the fonts with the system text size, like Text. Off by default so amounts keep their design size.

maxFontSizeMultipliernumberDefault 0

Upper bound for allowFontScaling, e.g. 1.3. 0 is no cap.

Size and alignment​

autoWidthboolean | 'auto'Default false, or 'auto' when reflowing

Whether the field sizes itself to its content. false takes its width from the parent the way a TextInput does, which is what makes it a drop-in. true always sizes to content. 'auto' infers it: on unless style gives a width or flex, which lets an amount grow as digits arrive, and is the default with transition="reflow".

textAlign'auto' | 'left' | 'center' | 'right'Default 'auto'

Where the text sits when the view is wider than it. 'auto' is the start edge of the layout direction, as TextInput; 'left' and 'right' are absolute. See Right-to-left.

adjustsFontSizeToFitbooleanDefault false

Scale the text down when it is wider than the view (give the view a fixed width in style), and back up when it fits again.

minimumFontScalenumberDefault 0.5

Smallest scale adjustsFontSizeToFit may apply, 0–1.

Multiline​

A wrapping field is drawn by the system view and is always 'text' mode: transition="reflow", a non-text mode and the affixes are ignored alongside it, with one warning each in development. See Multiline.

multilinebooleanDefault false

Let the text wrap onto more than one line. The return key inserts a line break unless submitBehavior says otherwise.

Lines tall before it scrolls. Omit to grow with the content.

rowsnumber

Alias of numberOfLines, matching TextInput.

textAlignVertical'auto' | 'top' | 'center' | 'bottom'Default 'auto'

Where the text sits in the box; 'auto' is the top.

scrollEnabledbooleanDefault true

Whether it scrolls once the text outgrows it.

Keyboard and return key​

keyboardType'default' | 'number-pad' | 'decimal-pad' | 'numeric' | 'email-address' | 'phone-pad' | 'url' | 'ascii-capable' | 'numbers-and-punctuation'Default by mode

Keyboard to show. 'number' mode defaults to 'decimal-pad' ('number-pad' with fractionDigits={0}), the others to 'default'.

inputMode'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url'

React Native's alias for keyboardType, following the HTML attribute and mapped with React Native's own table. Ignored when keyboardType is given. 'none' focuses without a keyboard, as in TextInput.

returnKeyType'default' | 'done' | 'go' | 'next' | 'search' | 'send'Default 'default'

Label of the return key.

enterKeyHint'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send'

React Native's alias for returnKeyType, following the HTML attribute. Ignored when returnKeyType is given.

keyboardAppearance'default' | 'light' | 'dark'iOSDefault 'default'

iOS: a light or dark keyboard; 'default' follows the system appearance.

enablesReturnKeyAutomaticallybooleanDefault false

Disables the return key until the field has text.

showSoftInputOnFocusbooleanDefault true

false keeps focus and the caret without the soft keyboard, for a field driven by an in-app keypad.

submitBehavior'blurAndSubmit' | 'submit' | 'newline'Default 'blurAndSubmit', 'newline' when multiline

What the return key does: 'blurAndSubmit' fires onSubmitEditing and dismisses the keyboard; 'submit' fires it and keeps focus, so a form can move to the next field itself; 'newline' inserts a line break (multiline only). The defaults are TextInput's.

Deprecated alias of submitBehavior, resolved as TextInput resolves it: false means 'submit' on a single-line field, true means 'blurAndSubmit' on a multiline one. Ignored when submitBehavior is given.

autoFocusbooleanDefault false

Focus the field when it mounts. Taken synchronously as soon as the view has a window, so on iOS a screen pushed over a focused field swaps the keyboard in place instead of dismissing and re-presenting it.

Editing behaviour​

autoCapitalize'none' | 'sentences' | 'words' | 'characters'Default 'sentences'

Auto-capitalisation in 'text' mode.

autoCorrectbooleanDefault true

Auto-correction in 'text' mode.

spellCheckbooleanDefault autoCorrect

Spell checking in 'text' mode.

secureTextEntrybooleanDefault false

Draws bullets and turns off autocorrect; the field keeps the real text for editing and autofill.

textContentTypestringiOSDefault ''

iOS textContentType, the autofill kind: 'username', 'password', 'oneTimeCode', …

autoCompletestringDefault ''

The cross-platform autofill hint, as TextInput's. Used as textContentType on iOS when that is not set.

selectTextOnFocusbooleanDefault false

Select all the text when the field gains focus.

clearTextOnFocusbooleanDefault false

Empty the field when it gains focus.

contextMenuHiddenbooleanDefault false

Hides the Cut / Copy / Paste menu.

Caret and selection​

cursorColorColorValueDefault platform tint

Caret colour.

selectionColorColorValueDefault platform tint

Selection highlight colour.

caretHiddenbooleanDefault false

Hides the caret.

selection{ start: number; end?: number }

The caret or selection to apply, in code points into the (formatted) text. onSelectionChange reports moves in the same units.

The reflow​

The opt-in glyph animation: every edit reflows from the old text to the new one. See The reflow.

transition'none' | 'reflow'Default 'none'

How the text changes. 'none' draws it the instant it changes: this is a text field first, and a TextInput does not animate its characters. 'reflow' runs the glyph engine, so characters that stay glide to their new place, new ones slide or fade in and removed ones leave alongside their neighbours. A multiline field is always 'none'.

durationnumberDefault 400

Duration in ms of the reflow played on every change. 0 snaps.

easing'expo' | 'easeOut' | 'easeInOut' | 'linear' | 'spring'Default 'expo'

Timing curve of the reflow. 'expo' is Torph's cubic-bezier(0.19, 1, 0.22, 1).

bouncenumberDefault 0.15

Overshoot of the 'spring' easing, 0–1.

effect'auto' | 'slide' | 'fade'Default 'auto'

How characters enter and leave. 'auto': digits and separators slide through the line box (digits from above, separators from below), other characters fade and scale.

Worklets​

With react-native-worklets installed, work can run on the UI thread inside the native edit, before a frame is drawn. See Worklets.

transformNitroInputTransform

A worklet that rewrites the text after every edit, synchronously on the UI thread: masks, custom formats, anything JS can express. It receives the edited text, the previous text and both selections (code point offsets) and returns the new text and optionally where the caret goes; null keeps the edit. In 'number' mode it runs after the native formatter. Create it once (module scope or useCallback): a new function re-registers the worklet.

Any event handler below marked 'worklet' runs on the UI thread instead of the JS one.

Events​

Every event is a superset of TextInput's: nativeEvent carries React Native's fields under React Native's names, so a handler written for a TextInput works unchanged, and the same fields are repeated at the top level, so ({ text }) => … reads better than (e) => e.nativeEvent.text.

onChangeText(text: string) => void

After every edit, with the field's (formatted) text. Marked 'worklet', it runs on the UI thread and can write shared values before the next frame.

onChange({ nativeEvent: { text, eventCount, target } }) => void

React Native's other change callback, fired alongside onChangeText with the same text. eventCount is the native edit counter, as in TextInput.

onChangeValue(value: number) => void

'number' mode: after every edit, with the numeric value; NaN when empty. A 'worklet' runs on the UI thread.

onChangeMask(formatted, extracted, tailPlaceholder, complete) => void

'mask' mode: after every edit, with the masked text, the characters the user contributed, what is still missing, and whether every mandatory slot is filled.

onFocus(event: NitroInputFocusEvent) => void

Focused. The event carries text, eventCount and target.

onBlur(event: NitroInputFocusEvent) => void

Blurred. Same event as onFocus.

onSubmitEditing(event: NitroInputTextEvent) => void

The return key was pressed.

onEndEditing(event: NitroInputTextEvent) => void

Editing finished: focus lost or the keyboard dismissed, as TextInput's.

onSelectionChange(event: NitroInputSelectionEvent) => void

The caret or selection moved. selection, start and end are code points.

onKeyPress(event: NitroInputKeyPressEvent) => void

A key was pressed, before the text changes: the character, 'Backspace' or 'Enter'.

onNativeRef(ref: NitroInputRef) => void

Receives the native Nitro object once the view is mounted.

Accessibility and identity​

The system field is the accessibility element, with the formatted text as its value ($1,234.50 USD reads as such). See Working with React Native.

The field's name for VoiceOver and TalkBack, forwarded to the system field. aria-label wins over the older spelling, as in TextInput. Without either, label is used.

Forwarded as accessibilityLabelledBy.

Fold into accessibilityState, as on any view.

Hides the field from assistive tech, as on any view.

Forwarded to the system field, the element e2e tools find. id wins over nativeID, as in TextInput.

styleViewStyle

The host view's style. Width comes from it unless autoWidth says otherwise; direction: 'rtl' flips a single field.

Methods (ref)​

The handle queues a call made before the native view exists and replays it once mounted, so focus() in an effect on mount works.

MethodDescription
focus()Focuses the field.
blur()Blurs it.
clear()Empties the field; with transition="reflow" the characters reflow away.
setText(text)Replaces the text (formatted in 'number' mode), caret at the end.
setValue(value)'number' mode: shows value formatted; NaN empties the field.
getText()The field's current (formatted) text.
getValue()'number' mode: the numeric value, NaN when empty.
isFocused()Whether the field has focus.
setSelection(start, end?)Moves the caret or selection; code points into the (formatted) text.
nativeThe native Nitro object, or null before mount.

Hook​

useNitroInputState(useSharedValue) returns the field's text, value, focused and selection as shared values, plus the worklet handlers to spread onto the field that keep them current. See the field's state as shared values.